package com.admin.business.voteEssentialInformation;

import com.admin.pojo.annotation.RepeatSubmit;
import com.alibaba.druid.util.StringUtils;
import com.admin.business.voteComment.VoteCommentDao;
import com.admin.business.voteOrgInfo.VoteOrgInfoDao;
import com.admin.business.voteOwnerMeeting.VoteOwnerMeetingDao;
import com.admin.business.voteRecommend.VoteRecommendDao;
import com.admin.business.voteRecommend.VoteRecommendService;
import com.admin.business.voteReconsideration.VoteReconsiderationDao;
import com.admin.business.voteRecord.VoteRecordDao;
import com.admin.business.voteRecord.VoteRecordService;
import com.admin.business.voteStatuteImg.VoteStatuteImgDao;
import com.admin.business.voteStep.VoteStepDao;
import com.admin.business.voteUser.VoteUserDao;
import com.admin.business.voteUser.VoteUserService;
import com.admin.business.voteVotingRecords.VoteVotingRecordsDao;
import com.admin.business.voteVotingSettings.VoteVotingSettingsDao;
import com.admin.utils.RandomStrUtil;
import com.admin.utils.RedisUtilKey;
import com.admin.utils.TimeUtil;
import com.admin.utils.UserCardInfoUtil;
import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @description: 首次成立业委会基本信息记录表
 * @create: 2022-07-08 19:04:49
 **/
@Service("voteEssentialInformation")
@Slf4j
public class VoteEssentialInformationService {

    @Resource
    VoteEssentialInformationDao voteEssentialInformationDao;


    @Resource
    VoteVotingRecordsDao voteVotingRecordsDao;

    @Resource
    VoteRecordDao voteRecordDao;

    @Resource
    VoteVotingSettingsDao voteVotingSettingsDao;

    @Resource
    VoteReconsiderationDao voteReconsiderationDao;

    //    一个人只能在报名业主只有一个
    @Resource
    VoteUserDao voteUserDao;

    //发起成立进度记录
    @Resource
    VoteStepDao voteStepDao;

    @Resource
    VoteStatuteImgDao voteStatuteImgDao; //违约文件信息

    @Resource
    VoteOwnerMeetingDao voteOwnerMeetingDao;

    @Resource
    VoteRecommendDao voteRecommendDao;
    @Resource
    VoteUserService voteUserService;

    @Autowired
    private RedisUtilKey redisTemplate;
    @Autowired
    private UserCardInfoUtil userCardInfoUtil;

    @Resource
    VoteCommentDao voteCommentDao;
    @Autowired
    TimeUtil timeUtil;
    @Resource
    VoteOrgInfoDao voteOrgInfoDao;

    //----------------------------------2022-11-09，代码重构---------------------------------

    /**
     * 校验选聘物业时刻可提前结束
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return verifyCheckOrgPass(CDO cdoRequest) {
        String essential_information_id = cdoRequest.getString("essential_information_id");
        if (StringUtils.isEmpty(essential_information_id)) return Return.valueOf(-2, "essential_information_id不可为空");
        CDO voteInfo = voteEssentialInformationDao.getVoteEssentialInformationById(Integer.parseInt(essential_information_id));
        if (voteInfo == null) return Return.valueOf(-2, "表决信息异常");
        String org_id = cdoRequest.getString("org_id");
        if (StringUtils.isEmpty(org_id)) return Return.valueOf(-2, "org_id不可为空");
        //判断是否可提前结束
        //由专有部分面积占比三分之二以上的业主且人数占比三分之二以上的业主参与表决
        //物业公司需专有部分面积过半数的业主参与表决且参与表决人数过半数的业主投票同意才能进行签署合同（忽略，参加及为同意）
        Double community_areass = voteInfo.getDouble("community_areass");//小区面积
        Double household_total = voteInfo.getDouble("household_total");//户数
        //参与报名户数
        CDO select = new CDO();
        select.set("essential_information_id", essential_information_id);
        select.set("recommend_state", 10);
        select.set("vote_user_id", org_id);
        Integer total = voteEssentialInformationDao.getVoteUserRecordListByCDOTotal(select);//参与数量
        Double participateTotal = Double.parseDouble(total.toString());
        Double areaSum = voteEssentialInformationDao.getAreaSumByCheckOrg(select);//参与面积
        areaSum = areaSum == null ? 0.0 : areaSum;
        Integer whetherPass = 0;//0.可结束 1.不可结束
        if (participateTotal / household_total < 0.66) {
            whetherPass = 1;
        }
        if (areaSum / community_areass < 0.66) {
            whetherPass = 1;
        }
        return Return.valueOf(whetherPass);
    }

    /**
     * 获取投票记录
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return getVoteListByCDO(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex") - 1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        String essential_information_id = cdoRequest.getString("essential_information_id");
        List<CDO> voteUserRecord = voteEssentialInformationDao.getVoteUserRecordListByCDO(cdoRequest);
        boolean isEndPage = false;
        if (voteUserRecord.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", voteUserRecord);
        Integer total = voteEssentialInformationDao.getVoteUserRecordListByCDOTotal(cdoRequest);
        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }


    @OpenApi
    public Return updateVoteEssentialInformationInfoCdo(CDO cdoRequest){
        Integer integer = voteEssentialInformationDao.updateVoteEssentialInformationDao(cdoRequest);
        return Return.valueOf(integer);
    }




    /**
     * 选聘物业，上传线下公示图片
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return checkOrgPublicity(CDO cdoRequest) {
        String id = cdoRequest.getString("id");
        String check_org_offline_publicity_img = cdoRequest.getString("check_org_offline_publicity_img");
        String check_org_filing_form_img = cdoRequest.getString("check_org_filing_form_img");
        String user_id = cdoRequest.getString("user_id");
        if (StringUtils.isEmpty(id)) return Return.valueOf(-2, "表决id不可为空");
        if (StringUtils.isEmpty(check_org_offline_publicity_img) || StringUtils.isEmpty(check_org_filing_form_img)) {
            return Return.valueOf(-2, "上传图片");
        }
        CDO updateVoteInfo = new CDO();
        updateVoteInfo.set("id", id);
        updateVoteInfo.set("check_org_offline_publicity_img", check_org_offline_publicity_img);
        updateVoteInfo.set("check_org_filing_form_img", check_org_filing_form_img);
        voteEssentialInformationDao.updateVoteEssentialInformationById(updateVoteInfo);
        //添加公示记录
        CDO addVoteRecord = new CDO();
        addVoteRecord.set("user_id", user_id);
        addVoteRecord.set("essential_information_id", id);
        addVoteRecord.set("vote_name", "选聘物业公司公示");
        addVoteRecord.set("vote_type", 21);
        this.addVoteRecord(addVoteRecord);
        return Return.SUCCESS;
    }

    /**
     * 选聘物业发起投票
     *
     * @return
     */
    @OpenApi
    public Return checkOrgLaunchVote(CDO cdoRequest) {
        String id = cdoRequest.getString("id");
        String check_org_vote_begin_time = cdoRequest.getString("check_org_vote_begin_time");
        String check_org_vote_end_time = cdoRequest.getString("check_org_vote_end_time");
        if (StringUtils.isEmpty(id)) return Return.valueOf(-2, "表决id不可为空");
        if (StringUtils.isEmpty(check_org_vote_begin_time) || StringUtils.isEmpty(check_org_vote_end_time)) {
            return Return.valueOf(-2, "请选择时间");
        }
        CDO updateVoteInfo = new CDO();
        updateVoteInfo.set("id", id);
        updateVoteInfo.set("check_org_vote_begin_time", check_org_vote_begin_time);
        updateVoteInfo.set("check_org_vote_end_time", check_org_vote_end_time);
        voteEssentialInformationDao.updateVoteEssentialInformationById(updateVoteInfo);
        CDO selectOrg = new CDO();
        selectOrg.set("p_id", id);
        selectOrg.set("recordFrom", 0);
        selectOrg.set("recordSize", 10);
        List<CDO> orgList = voteOrgInfoDao.getVoteOrgInfoListPage(selectOrg);
        for (CDO orgInfo : orgList) {
            if (orgInfo.getInteger("org_vote_type") == 0) {
                CDO updateOrg = new CDO();
                updateOrg.set("id", orgInfo.getString("id"));
                updateOrg.set("org_vote_type", 1);
                voteOrgInfoDao.updateVoteOrgInfoById(updateOrg);
                break;
            }
        }
        //添加步骤
        CDO addVoteStep = new CDO();
        addVoteStep.set("step_id", id);
        addVoteStep.set("user_id", cdoRequest.getString("user_id"));
        //数据备注
        addVoteStep.set("planned_speed", "发起选聘物业投票公示");
        addVoteStep.set("complete_state", 1);
        //到第几大步
        addVoteStep.set("step_big", 4);
        //到第几小步
        addVoteStep.set("step_small", 2);
        this.publicAdditionsAddVoteStep(addVoteStep);
        return Return.SUCCESS;
    }


    /**
     * 获取议题集合
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return getThingsListByOwnerApp(CDO cdoRequest) {
        String essential_information_id = cdoRequest.getString("essential_information_id");
        if (StringUtils.isEmpty(essential_information_id)) return Return.valueOf(-2, "essential_information_id不可为空");
        CDO selectThings = new CDO();
        selectThings.set("essential_information_id", essential_information_id);
        selectThings.set("statute_state", 6);
        String userId = cdoRequest.getString("userId");
        String ownerSelect = cdoRequest.getString("ownerSelect");
        String ownerAppSelect = cdoRequest.getString("ownerAppSelect");
        List<CDO> voteStatuteImgList = voteStatuteImgDao.getVoteStatuteImgList(selectThings);
        for (CDO thingsInfo : voteStatuteImgList) {
            String id = thingsInfo.getString("id");
            //查询当前操作人是否同意过
            if (!StringUtils.isEmpty(userId) && !StringUtils.isEmpty(ownerSelect)) {
                CDO select = new CDO();
                select.set("statute_id", id);
                select.set("user_id", userId);
                select.set("record_state", 1);
                if (!StringUtils.isEmpty(ownerAppSelect)) select.set("record_type", 1);//1.业主身份同意
                int recordTotal = voteVotingRecordsDao.getVoteVotingRecordsCount(select);
                thingsInfo.set("agreeClickFlag", recordTotal > 0 ? true : false);
            }
        }
        return Return.valueOf(voteStatuteImgList);
    }

    /**
     * 解聘物业第三步确认公示
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return surePublicityFire(CDO cdoRequest) {
        String id = cdoRequest.getString("id");
        String user_id = cdoRequest.getString("user_id");
        List<CDO> voteThingsList = cdoRequest.getCDOList("voteThingsList");
        List<CDO> voteOtherThingsList = cdoRequest.getCDOList("voteOtherThingsList");
        CDO lastInfo = voteThingsList.get(voteThingsList.size() - 1);
        if (!lastInfo.getBoolean("checkFlag")) {
            voteThingsList = null;
        }
        CDO thingsCdo = new CDO();
        thingsCdo.set("voteThingsList", voteThingsList);
        thingsCdo.set("voteOtherThingsList", voteOtherThingsList);
        CDO updateVoteInfo = new CDO();
        updateVoteInfo.set("id", id);
        updateVoteInfo.set("four_owner_programme_img", cdoRequest.getString("four_owner_programme_img"));
        updateVoteInfo.set("vote_things", thingsCdo.toString());
        voteEssentialInformationDao.updateVoteEssentialInformationById(updateVoteInfo);
        //添加业主规约公示记录
        CDO addVoteRecord = new CDO();
        addVoteRecord.set("user_id", user_id);
        addVoteRecord.set("essential_information_id", id);
        addVoteRecord.set("vote_name", "业主规约公示");
        addVoteRecord.set("vote_type", 4);
        this.addVoteRecord(addVoteRecord);
        return Return.SUCCESS;
    }

    /**
     * 解聘物业，第二步委员身份，手动添加委员信息
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return manualAddMembersInfo(CDO cdoRequest) {
        String full_name = cdoRequest.getString("full_name");
        String telephone = cdoRequest.getString("telephone");
        //添加委员的用户id
        String userId = this.getUserIdByUserNameAndTel(full_name, telephone);
        if (StringUtils.isEmpty(userId)) {
            return Return.valueOf(-2, "该用户未注册助业网会员，请先注册！");
        }
        String essential_information_id = cdoRequest.getString("essential_information_id");
        if (StringUtils.isEmpty(essential_information_id)) {
            return Return.valueOf(-2, "essential_information_id不可为空");
        }
        CDO voteInfo = voteEssentialInformationDao.getVoteEssentialInformationById(Integer.parseInt(essential_information_id));
        if (voteInfo == null) return Return.valueOf(-2, "表决信息异常");
        //查询该表决该用户是否已有用户数据
        CDO voteUserInfo = voteEssentialInformationDao.getVoteUserInfoByVoeIdAndUserId(userId, essential_information_id);
        if (voteUserInfo != null) {
            //修改
            cdoRequest.set("id", voteUserInfo.getString("id"));
            voteUserDao.updateVoteUserById(cdoRequest);
        } else {
            cdoRequest.set("user_id", userId);
            cdoRequest.set("user_id_zyw", userId);
            //添加
            //判断委员数量，是否可添加委员信息
            CDO selectMemberTotal = new CDO();
            selectMemberTotal.set("essential_information_id", essential_information_id);
            selectMemberTotal.set("committee_member_status", 1);
            int memberTotal = voteUserDao.getVoteUserListCount(selectMemberTotal);
            Integer industry_committee_total = voteInfo.getInteger("industry_committee_total");
            if (industry_committee_total <= memberTotal) {
                return Return.valueOf(-2, "委员人数已满，请勿再次添加！");
            }
            voteUserDao.addVoteUser(cdoRequest);
        }
        return Return.SUCCESS;
    }

    /**
     * 确认工作组组长
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return confirmWorkingGroupsLeader(CDO cdoRequest) {
        String id = cdoRequest.getString("id");
        if (StringUtils.isEmpty(id)) {
            return Return.valueOf(-2, "id不可为空");
        }
        CDO voteInfo = voteEssentialInformationDao.getVoteEssentialInformationById(Integer.parseInt(id));
        if (voteInfo == null) return Return.valueOf(-2, "表决信息异常");

        CDO selectUserList = new CDO();
        selectUserList.set("essential_information_id", id);
        selectUserList.set("selectWaitPreparation", 1);
        selectUserList.set("workGroupOrder", 1);
        selectUserList.set("recordFrom", 0);
        selectUserList.set("recordSize", 1);
        List<CDO> voteUserList = voteEssentialInformationDao.getVoteUserListByCDO(selectUserList);
        if (voteUserList == null || voteUserList.size() == 0) {
            return Return.valueOf(-2, "工作组信息异常，请联系客服");
        }

        //修改工作组组长投票结束
        CDO select = new CDO();
        select.set("essential_information_id", id);
        //13.工作组组长投票
        select.set("vote_type", 13);
        CDO recordInfo = voteRecordDao.getVoteRecordByCdo(select);
        if (recordInfo == null) return Return.valueOf(-2, "工作组组长公示信息异常");
        CDO updateVoteRecord = new CDO();
        updateVoteRecord.set("id", recordInfo.getString("id"));
        updateVoteRecord.set("vote_state", 1);
        voteRecordDao.updateVoteRecordById(updateVoteRecord);

        CDO leaderInfo = voteUserList.get(0);
        //修改该人为工作组组长
        CDO updateUserInfo = new CDO();
        updateUserInfo.set("id", leaderInfo.getString("id"));
        //0.成员 1.组长
        updateUserInfo.set("preparation_state", 1);
        voteUserDao.updateVoteUserById(updateUserInfo);

        //修改表决信息为已有组长
        CDO updateVoteInfo = new CDO();
        updateVoteInfo.set("id", id);
        updateVoteInfo.set("preparation_status", 1);
        updateVoteInfo.set("preparation_vote_user_id", leaderInfo.getString("user_id"));
        updateVoteInfo.set("preparation_telephone", leaderInfo.getString("telephone"));
        voteEssentialInformationDao.updateVoteEssentialInformationById(updateVoteInfo);

        //添加步骤
        CDO addVoteStep = new CDO();
        addVoteStep.set("step_id", id);
        addVoteStep.set("user_id", cdoRequest.getString("user_id"));
        addVoteStep.set("property", voteInfo.getString("community_name"));
        //数据备注
        addVoteStep.set("planned_speed", "确认工作组组长信息");
        addVoteStep.set("complete_state", 1);
        //到第几大步
        addVoteStep.set("step_big", 3);
        //到第几小步
        addVoteStep.set("step_small", 1);
        this.publicAdditionsAddVoteStep(addVoteStep);
        return Return.SUCCESS;
    }

    /**
     * 发起工作组组长投票
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return addFirePropertyWorkGrouper(CDO cdoRequest) {
        String id = cdoRequest.getString("id");
        if (StringUtils.isEmpty(id)) {
            return Return.valueOf(-2, "表决id不可为空");
        }
        CDO voteInfo = voteEssentialInformationDao.getVoteEssentialInformationById(Integer.parseInt(id));
        if (voteInfo == null) return Return.valueOf(-2, "表决信息异常");

        //工作组组长投票结束时间
        String leader_vote_end_time = cdoRequest.getString("leader_vote_end_time");
        if (StringUtils.isEmpty(leader_vote_end_time)) {
            return Return.valueOf(-2, "请选择投票结束时间");
        }
        CDO updateVoteInfo = new CDO();
        updateVoteInfo.set("id", id);
        updateVoteInfo.set("leader_vote_end_time", leader_vote_end_time);
        voteEssentialInformationDao.updateVoteEssentialInformationById(updateVoteInfo);

        //添加工作组组长投票记录
        CDO addVote = new CDO();
        addVote.set("user_id", cdoRequest.getString("user_id"));
        addVote.set("essential_information_id", id);
        addVote.set("vote_name", "工作组组长投票");
        addVote.set("vote_type", 13);//工作组组长投票
        this.addVoteRecord(addVote);

        //添加步骤
        CDO addVoteStep = new CDO();
        addVoteStep.set("step_id", id);
        addVoteStep.set("user_id", cdoRequest.getString("user_id"));
        addVoteStep.set("property", voteInfo.getString("community_name"));
        //数据备注
        addVoteStep.set("planned_speed", "发起工作组组长投票");
        addVoteStep.set("complete_state", 1);
        //到第几大步
        addVoteStep.set("step_big", 2);
        //到第几小步
        addVoteStep.set("step_small", 9);
        this.publicAdditionsAddVoteStep(addVoteStep);
        return Return.SUCCESS;
    }


    /**
     * 跳跃投票步骤  2023-5-5
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return jumpVoteSteps(CDO cdoRequest) {
        String id = cdoRequest.getString("id");
        if (StringUtils.isEmpty(id)) return Return.valueOf(-2, "投票id不可为空");
        String userId = cdoRequest.getString("userId");
        CDO voteInfo = voteEssentialInformationDao.getVoteEssentialInformationById(Integer.parseInt(id));
        if (voteInfo == null) return Return.valueOf(-2, "表决信息异常");
        Integer step_big = cdoRequest.getInteger("step_big");
        Integer step_small = cdoRequest.getInteger("step_small");
        if (step_big == null || step_small == null) return Return.valueOf(-2, "步骤信息不可为空");
        String step_remark = cdoRequest.getString("step_remark");
        if (StringUtils.isEmpty(step_remark)) return Return.valueOf(-2, "step_remark步骤备注不可为空");

        //1.申请成立业主大会 2.解聘现物业公司   3.选聘物业公司
        Integer vote_type = voteInfo.getInteger("vote_type");
        String msg = null;
        switch (vote_type) {
            case 1:
                msg = this.setUpOwnersMeetingJump(cdoRequest, voteInfo);
                break;
            case 2:
                msg = this.firePropertyJump(cdoRequest, voteInfo);
                break;
            case 3:
                msg = this.selectionPropertyJump(cdoRequest, voteInfo);
                break;
        }
        if (!StringUtils.isEmpty(msg)) {
            return Return.valueOf(-2, msg);
        }
        //添加步骤
        CDO addVoteStep = new CDO();
        addVoteStep.set("step_id", id);
        addVoteStep.set("user_id", userId);
        addVoteStep.set("property", voteInfo.getString("community_name"));
        //数据备注
        addVoteStep.set("planned_speed", step_remark);
        addVoteStep.set("complete_state", 1);
        //到第几大步
        addVoteStep.set("step_big", step_big);
        //到第几小步
        addVoteStep.set("step_small", step_small);
        this.publicAdditionsAddVoteStep(addVoteStep);
        return Return.SUCCESS;
    }

    /**
     * 解聘物业跳步
     *
     * @param cdoRequest
     * @param voteInfo
     * @return
     */
    public String firePropertyJump(CDO cdoRequest, CDO voteInfo) {
        String id = cdoRequest.getString("id");
        String userId = cdoRequest.getString("userId");
        Integer step_big = cdoRequest.getInteger("step_big");
        Integer step_small = cdoRequest.getInteger("step_small");
        String step_remark = cdoRequest.getString("step_remark");
        //1.业主  2.业委会委员
        Integer identity_type = cdoRequest.getInteger("identity_type");

        //------------------------------------参数校验------------------------------------------------
        //工作组人员集合
        List<CDO> preparationList = cdoRequest.getCDOList("preparationList");
        if (step_big < 3) {
            if (identity_type == 2) {
                //操作人业委会身份
                String telephone = cdoRequest.getString("telephone");
                if (StringUtils.isEmpty(telephone)) return "请填写手机号";

                String building_number = cdoRequest.getString("building_number");
                if (StringUtils.isEmpty(building_number)) return "请填写楼宇信息";

                String housing_area = cdoRequest.getString("housing_area");
                if (StringUtils.isEmpty(housing_area)) return "请填写房间面积";

                String id_card_just = cdoRequest.getString("id_card_just");
                if (StringUtils.isEmpty(id_card_just)) return "请上传身份证正面";

                String id_card_back = cdoRequest.getString("id_card_back");
                if (StringUtils.isEmpty(id_card_back)) return "请上传身份证反面";

                String director = cdoRequest.getString("director");
                if (StringUtils.isEmpty(director)) return "请选择委员身份";

                String deputy_director = cdoRequest.getString("deputy_director");
                if (StringUtils.isEmpty(deputy_director)) return "请选择委员身份";

                String userVoteId = cdoRequest.getString("userVoteId");
                if (StringUtils.isEmpty(userVoteId)) return "操作人投票用户id不可为空";

                //校验委员信息
                List<CDO> membersList = cdoRequest.getCDOList("membersList");
                if (membersList == null) return "请上传委员信息";
                for (CDO memberInfo : membersList) {
                    //添加委员的用户id
                    String memberUserId = this.getUserIdByUserNameAndTel(memberInfo.getString("full_name"), memberInfo.getString("telephone"));
                    if (StringUtils.isEmpty(memberUserId)) {
                        return memberInfo.getString("full_name") + "未注册助业网会员，请先注册！";
                    }
                    Integer industry_committee_total = voteInfo.getInteger("industry_committee_total");
                    if (membersList.size() < industry_committee_total) {
                        return "委员人数不足";
                    }
                    if (membersList.size() > industry_committee_total) {
                        return "委员人数过多";
                    }
                }
            }
            if (identity_type == 1) {
                //工作组信息
                String preparations_number = cdoRequest.getString("preparations_number");
                if (StringUtils.isEmpty(preparations_number)) {
                    return "请填写工作组人数";
                }
                if(preparationList == null){
                    return "请填写工作组信息";
                }
                if(preparationList.size() != Integer.parseInt(preparations_number)){
                    return "工作组数量错误";
                }
                for (CDO preparationInfo : preparationList) {
                    String preparationName = preparationInfo.getString("preparation_name");
                    String preparationTelephone = preparationInfo.getString("preparation_telephone");
                    String preparationUserId2 = this.getUserIdByUserNameAndTel(preparationName, preparationTelephone);
                    if (StringUtils.isEmpty(preparationUserId2)) {
                        return "工作组成员必须是助业网会员";
                    }
                    preparationInfo.set("preparationUserId", preparationUserId2);
                }
            }
        }
        //委托人信息
        List<CDO> clientList = cdoRequest.getCDOList("clientList");
        if (step_big < 4) {
            List<CDO> voteThingsList = cdoRequest.getCDOList("voteThingsList");
            List<CDO> voteOtherThingsList = cdoRequest.getCDOList("voteOtherThingsList");
            if (voteThingsList == null) {
                return "请选择表决事项";
            }
            CDO heldOwnerCongress = cdoRequest.getCDO("heldOwnerCongress");
            if (heldOwnerCongress == null) {
                return "请上传决议方案";
            }
            //无业委会，招募委托人
            if(identity_type == 1){
                //添加委托人
                if(clientList == null){
                    return "请填写委托人信息";
                }
                for (CDO clientInfo : clientList) {
                    String preparationName = clientInfo.getString("preparation_name");
                    String preparationTelephone = clientInfo.getString("preparation_telephone");
                    String preparationUserId2 = this.getUserIdByUserNameAndTel(preparationName, preparationTelephone);
                    if (StringUtils.isEmpty(preparationUserId2)) {
                        return "委托人成员必须是助业网会员";
                    }
                    clientInfo.set("preparationUserId", preparationUserId2);
                }
            }
        }
        if(step_big < 5){
            //投票达到法定要求提前结束：1是，0否
            String six_end_voting = cdoRequest.getString("six_end_voting");
            //召开大会开始时间
            String six_holding_time = cdoRequest.getString("six_holding_time");
            //召开大会结束时间
            String six_holding_end_time = cdoRequest.getString("six_holding_end_time");
            //可延长时间
            String six_expand_time = cdoRequest.getString("six_expand_time");
            //会议地点
            String six_meeting_place = cdoRequest.getString("six_meeting_place");
            if(StringUtils.isEmpty(six_end_voting)){
                return "six_end_voting不可为空";
            }
            if(StringUtils.isEmpty(six_holding_time)){
                return "six_holding_time不可为空";
            }
            if(StringUtils.isEmpty(six_holding_end_time)){
                return "six_holding_end_time不可为空";
            }
            if(StringUtils.isEmpty(six_expand_time)){
                return "six_expand_time不可为空";
            }
            if(StringUtils.isEmpty(six_meeting_place)){
                return "six_meeting_place不可为空";
            }
        }

        //------------------------------------业务处理-------------------------------------------------
        if (step_big < 3) {
            if (identity_type == 2) {
                //操作人业委会身份
                String telephone = cdoRequest.getString("telephone");
                String building_number = cdoRequest.getString("building_number");
                String housing_area = cdoRequest.getString("housing_area");
                String id_card_just = cdoRequest.getString("id_card_just");
                String id_card_back = cdoRequest.getString("id_card_back");
                String director = cdoRequest.getString("director");
                String deputy_director = cdoRequest.getString("deputy_director");
                String userVoteId = cdoRequest.getString("userVoteId");
                CDO updateUserInfo = new CDO();
                updateUserInfo.set("id", userVoteId);
                updateUserInfo.set("telephone", telephone);
                updateUserInfo.set("building_number", building_number);
                updateUserInfo.set("housing_area", housing_area);
                updateUserInfo.set("id_card_just", id_card_just);
                updateUserInfo.set("id_card_back", id_card_back);
                updateUserInfo.set("director", director);
                updateUserInfo.set("deputy_director", deputy_director);
                voteUserDao.updateVoteUserById(updateUserInfo);

                //添加委员信息
                List<CDO> membersList = cdoRequest.getCDOList("membersList");
                for (CDO memberInfo : membersList) {
                    String memberUserId = this.getUserIdByUserNameAndTel(memberInfo.getString("full_name"), memberInfo.getString("telephone"));
                    CDO voteUserInfo = voteEssentialInformationDao.getVoteUserInfoByVoeIdAndUserId(memberUserId, id);
                    if (voteUserInfo != null) {
                        //修改
                        memberInfo.set("id", voteUserInfo.getString("id"));
                        voteUserDao.updateVoteUserById(memberInfo);
                    } else {
                        memberInfo.set("user_id", memberUserId);
                        memberInfo.set("user_id_zyw", memberUserId);
                        voteUserDao.addVoteUser(memberInfo);
                    }
                }
                //添加解聘事项至vote_statute_img
                String vote_things = voteInfo.getString("vote_things");
                List<String> thingsList = new ArrayList<>();
                if (!StringUtils.isEmpty(vote_things)) {
                    CDO voteThingsCdo = voteInfo.getCDO("vote_things");
                    if (voteThingsCdo != null) {
                        List<CDO> voteThingsListAdd = voteThingsCdo.getCDOList("voteThingsList");
                        List<CDO> voteOtherThingsListAdd = voteThingsCdo.getCDOList("voteOtherThingsList");
                        for (CDO cdo : voteThingsListAdd) {
                            if (cdo.getBoolean("checkFlag")) {
                                thingsList.add(cdo.getString("text"));
                            }
                        }
                        for (CDO thingsCdo : voteOtherThingsListAdd) {
                            thingsList.add(thingsCdo.getString("otherThings"));
                        }
                    }
                }
                int statute_edition = 0;
                for (String thingsText : thingsList) {
                    if (StringUtils.isEmpty(thingsText)) {
                        continue;
                    }
                    statute_edition++;
                    CDO addThing = new CDO();
                    addThing.set("essential_information_id", id);
                    addThing.set("statute_state", 6);
                    addThing.set("statute_edition", statute_edition);
                    addThing.set("things_text", thingsText);
                    voteStatuteImgDao.addVoteStatuteImg(addThing);
                }
                //添加解聘物业业主大会投票
                //添加投票公示信息
                CDO addVoteRecord = new CDO();
                addVoteRecord.set("essential_information_id", id);
                addVoteRecord.set("vote_name", "解聘现物业业主大会投票");
                addVoteRecord.set("vote_type", 17);//解聘现物业业主大会投票
                this.addVoteRecord(addVoteRecord);
            }
            if (identity_type == 1) {
                //添加工作组成员信息
                for (CDO preparationMemberInfo : preparationList) {
                    CDO addUserInfo = new CDO();
                    addUserInfo.set("user_id", preparationMemberInfo.getString("preparationUserId"));
                    addUserInfo.set("user_id_zyw", preparationMemberInfo.getString("preparationUserId"));
                    addUserInfo.set("essential_information_id", id);
                    addUserInfo.set("full_name", preparationMemberInfo.getString("preparation_name"));
                    addUserInfo.set("telephone", preparationMemberInfo.getString("preparation_telephone"));
                    addUserInfo.set("company", preparationMemberInfo.getString("company"));
                    addUserInfo.set("preparation_status", 1);//是否作组成员：1是，0否
                    addUserInfo.set("perparation_add_state", 1);//1.手动添加
                    addUserInfo.set("house_name", voteInfo.getString("community_name"));//小区名称  无意义参数
                    this.publicAdditionsAddOrUpdateVoteUser(addUserInfo);
                }
            }
        }
        if (step_big < 4){
            List<CDO> voteThingsList = cdoRequest.getCDOList("voteThingsList");
            List<CDO> voteOtherThingsList = cdoRequest.getCDOList("voteOtherThingsList");
            CDO lastInfo = voteThingsList.get(voteThingsList.size() - 1);
            if (!lastInfo.getBoolean("checkFlag")) {
                voteThingsList = null;
            }
            CDO thingsCdo = new CDO();
            thingsCdo.set("voteThingsList", voteThingsList);
            thingsCdo.set("voteOtherThingsList", voteOtherThingsList);
            CDO updateVoteInfo = new CDO();
            updateVoteInfo.set("id", id);
            updateVoteInfo.set("four_owner_programme_img", cdoRequest.getString("four_owner_programme_img"));
            updateVoteInfo.set("vote_things", thingsCdo.toString());
            voteEssentialInformationDao.updateVoteEssentialInformationById(updateVoteInfo);
            //添加业主规约公示记录
            CDO addVoteRecord = new CDO();
            addVoteRecord.set("user_id", userId);
            addVoteRecord.set("essential_information_id", id);
            addVoteRecord.set("vote_name", "业主规约公示");
            addVoteRecord.set("vote_type", 4);
            this.addVoteRecord(addVoteRecord);
            CDO heldOwnerCongress = cdoRequest.getCDO("heldOwnerCongress");
            heldOwnerCongress.set("essential_information_id", id);
            heldOwnerCongress.set("user_id", userId);
            voteStatuteImgDao.addVoteStatuteImg(heldOwnerCongress);
            //无业委会，招募委托人
            if(identity_type == 1){
                //添加委托人
                //先编辑之前工作组状态为非工作组
                CDO updateClient = new CDO();
                updateClient.set("essential_information_id",id);
                voteEssentialInformationDao.updatePreparationsStateByCDO(updateClient);
                //添加委托人成员信息
                for (CDO clientInfo : clientList) {
                    CDO addUserInfo = new CDO();
                    addUserInfo.set("user_id", clientInfo.getString("preparationUserId"));
                    addUserInfo.set("user_id_zyw", clientInfo.getString("preparationUserId"));
                    addUserInfo.set("essential_information_id", id);
                    addUserInfo.set("full_name", clientInfo.getString("preparation_name"));
                    addUserInfo.set("telephone", clientInfo.getString("preparation_telephone"));
                    addUserInfo.set("company", clientInfo.getString("company"));
                    addUserInfo.set("preparation_status", 1);//是否作组成员：1是，0否
                    addUserInfo.set("perparation_add_state", 1);//1.手动添加
                    addUserInfo.set("house_name", voteInfo.getString("community_name"));//小区名称  无意义参数
                    this.publicAdditionsAddOrUpdateVoteUser(addUserInfo);
                }
            }
        }
        if(step_big < 5){
            //投票达到法定要求提前结束：1是，0否
            String six_end_voting = cdoRequest.getString("six_end_voting");
            //召开大会开始时间
            String six_holding_time = cdoRequest.getString("six_holding_time");
            //召开大会结束时间
            String six_holding_end_time = cdoRequest.getString("six_holding_end_time");
            //可延长时间
            String six_expand_time = cdoRequest.getString("six_expand_time");
            //会议地点
            String six_meeting_place = cdoRequest.getString("six_meeting_place");
            CDO updateBaseInfo = new CDO();
            updateBaseInfo.set("id",id);
            updateBaseInfo.set("six_end_voting",six_end_voting);
            updateBaseInfo.set("six_holding_time",six_holding_time);
            updateBaseInfo.set("six_holding_end_time",six_holding_end_time);
            updateBaseInfo.set("six_expand_time",six_expand_time);
            updateBaseInfo.set("six_meeting_place",six_meeting_place);
            voteEssentialInformationDao.updateVoteEssentialInformationById(updateBaseInfo);
        }
        return null;
    }

    /**
     * 选聘物业公司跳步
     *
     * @param cdoRequest
     * @param voteInfo
     * @return
     */
    public String selectionPropertyJump(CDO cdoRequest, CDO voteInfo) {
        String id = cdoRequest.getString("id");
        String userId = cdoRequest.getString("userId");
        Integer step_big = cdoRequest.getInteger("step_big");
        Integer step_small = cdoRequest.getInteger("step_small");
        String step_remark = cdoRequest.getString("step_remark");
        //1.业主  2.业委会委员
        Integer identity_type = cdoRequest.getInteger("identity_type");

        //工作组人员集合
        List<CDO> preparationList = cdoRequest.getCDOList("preparationList");
        if (step_big < 3) {
            if (identity_type == 2) {
                //操作人业委会身份
                String telephone = cdoRequest.getString("telephone");
                if (StringUtils.isEmpty(telephone)) return "请填写手机号";

                String building_number = cdoRequest.getString("building_number");
                if (StringUtils.isEmpty(building_number)) return "请填写楼宇信息";

                String housing_area = cdoRequest.getString("housing_area");
                if (StringUtils.isEmpty(housing_area)) return "请填写房间面积";

                String id_card_just = cdoRequest.getString("id_card_just");
                if (StringUtils.isEmpty(id_card_just)) return "请上传身份证正面";

                String id_card_back = cdoRequest.getString("id_card_back");
                if (StringUtils.isEmpty(id_card_back)) return "请上传身份证反面";

                String director = cdoRequest.getString("director");
                if (StringUtils.isEmpty(director)) return "请选择委员身份";

                String deputy_director = cdoRequest.getString("deputy_director");
                if (StringUtils.isEmpty(deputy_director)) return "请选择委员身份";

                String userVoteId = cdoRequest.getString("userVoteId");
                if (StringUtils.isEmpty(userVoteId)) return "操作人投票用户id不可为空";

                //校验委员信息
                List<CDO> membersList = cdoRequest.getCDOList("membersList");
                if (membersList == null) return "请上传委员信息";
                for (CDO memberInfo : membersList) {
                    //添加委员的用户id
                    String memberUserId = this.getUserIdByUserNameAndTel(memberInfo.getString("full_name"), memberInfo.getString("telephone"));
                    if (StringUtils.isEmpty(memberUserId)) {
                        return memberInfo.getString("full_name") + "未注册助业网会员，请先注册！";
                    }
                    Integer industry_committee_total = voteInfo.getInteger("industry_committee_total");
                    if (membersList.size() < industry_committee_total) {
                        return "委员人数不足";
                    }
                    if (membersList.size() > industry_committee_total) {
                        return "委员人数过多";
                    }
                }
            }
            if (identity_type == 1) {
                //工作组信息
                String preparations_number = cdoRequest.getString("preparations_number");
                if (StringUtils.isEmpty(preparations_number)) {
                    return "请填写工作组人数";
                }
                for (CDO preparationInfo : preparationList) {
                    String preparationName = preparationInfo.getString("preparation_name");
                    String preparationTelephone = preparationInfo.getString("preparation_telephone");
                    String preparationUserId2 = this.getUserIdByUserNameAndTel(preparationName, preparationTelephone);
                    if (StringUtils.isEmpty(preparationUserId2)) {
                        return "工作组成员必须是助业网会员";
                    }
                    preparationInfo.set("preparationUserId", preparationUserId2);
                }
            }
        }

        if (step_big < 4) {
            CDO heldOwnerCongress = cdoRequest.getCDO("heldOwnerCongress");
            if (heldOwnerCongress == null) {
                return "请上传决议方案";
            }
            //竞争性谈判小组
            List<CDO> negotiatingTeamList = cdoRequest.getCDOList("negotiatingTeamList");
            if (negotiatingTeamList == null) return "请上传竞争性谈判小组信息";
            for (CDO negotiatingInfo : negotiatingTeamList) {
                String full_name = negotiatingInfo.getString("full_name");
                String telephone = negotiatingInfo.getString("telephone");
                String company = negotiatingInfo.getString("company");
                if (StringUtils.isEmpty(full_name) || StringUtils.isEmpty(telephone) || StringUtils.isEmpty(company)) {
                    return "请填写完整竞争性谈判小组人员信息";
                }
                String teamUserId = this.getUserIdByUserNameAndTel(full_name, telephone);
                if (StringUtils.isEmpty(teamUserId)) {
                    return full_name + "未注册助业网会员，请先注册！";
                }
                //添加谈判小组，已经是小组成员，不可再次添加
                CDO publicCount = new CDO();
                publicCount.set("essential_information_id", id);
                publicCount.set("user_id", userId);
                CDO voteUserInfo = voteUserDao.getVoteUserInfoByCDO(publicCount);
                if (voteUserInfo != null) {
                    String whether_negotiation_team = voteUserInfo.getString("whether_negotiation_team");
                    if ("1".equals(whether_negotiation_team)) {
                        return full_name + "已为谈判小组成员，请勿再次添加";
                    }
                }
            }
        }

        if (step_big < 5) {
            //添加物业公司信息
            List<CDO> orgInfoList = cdoRequest.getCDOList("orgInfoList");
            if (orgInfoList == null) {
                return "请填写物业公司信息";
            }
            if (orgInfoList.size() != 3) {
                return "物业公司数量为三";
            }
            for (CDO orgInfo : orgInfoList) {
                String msg = this.verifyCheckOrgAddOrgInfo(orgInfo);
                if (StringUtils.isEmpty(msg)) {
                    return msg;
                }
            }
            String check_org_vote_begin_time = cdoRequest.getString("check_org_vote_begin_time");
            String check_org_vote_end_time = cdoRequest.getString("check_org_vote_end_time");
            if (StringUtils.isEmpty(check_org_vote_begin_time)) {
                return "选聘物业投票开始时间";
            }
            if (StringUtils.isEmpty(check_org_vote_end_time)) {
                return "选聘物业投票结束时间";
            }
        }

        if (step_big < 3) {
            if (identity_type == 2) {
                //操作人业委会身份
                String telephone = cdoRequest.getString("telephone");
                String building_number = cdoRequest.getString("building_number");
                String housing_area = cdoRequest.getString("housing_area");
                String id_card_just = cdoRequest.getString("id_card_just");
                String id_card_back = cdoRequest.getString("id_card_back");
                String director = cdoRequest.getString("director");
                String deputy_director = cdoRequest.getString("deputy_director");
                String userVoteId = cdoRequest.getString("userVoteId");
                CDO updateUserInfo = new CDO();
                updateUserInfo.set("id", userVoteId);
                updateUserInfo.set("telephone", telephone);
                updateUserInfo.set("building_number", building_number);
                updateUserInfo.set("housing_area", housing_area);
                updateUserInfo.set("id_card_just", id_card_just);
                updateUserInfo.set("id_card_back", id_card_back);
                updateUserInfo.set("director", director);
                updateUserInfo.set("deputy_director", deputy_director);
                voteUserDao.updateVoteUserById(updateUserInfo);
                //添加委员信息
                List<CDO> membersList = cdoRequest.getCDOList("membersList");
                for (CDO memberInfo : membersList) {
                    String memberUserId = this.getUserIdByUserNameAndTel(memberInfo.getString("full_name"), memberInfo.getString("telephone"));
                    CDO voteUserInfo = voteEssentialInformationDao.getVoteUserInfoByVoeIdAndUserId(memberUserId, id);
                    if (voteUserInfo != null) {
                        //修改
                        memberInfo.set("id", voteUserInfo.getString("id"));
                        voteUserDao.updateVoteUserById(memberInfo);
                    } else {
                        memberInfo.set("user_id", memberUserId);
                        memberInfo.set("user_id_zyw", memberUserId);
                        voteUserDao.addVoteUser(memberInfo);
                    }
                }
            }
            if (identity_type == 1) {
                //添加工作组成员信息
                for (CDO preparationMemberInfo : preparationList) {
                    CDO addUserInfo = new CDO();
                    addUserInfo.set("user_id", preparationMemberInfo.getString("preparationUserId"));
                    addUserInfo.set("user_id_zyw", preparationMemberInfo.getString("preparationUserId"));
                    addUserInfo.set("essential_information_id", id);
                    addUserInfo.set("full_name", preparationMemberInfo.getString("preparation_name"));
                    addUserInfo.set("telephone", preparationMemberInfo.getString("preparation_telephone"));
                    addUserInfo.set("company", preparationMemberInfo.getString("company"));
                    addUserInfo.set("preparation_status", 1);//是否作组成员：1是，0否
                    addUserInfo.set("perparation_add_state", 1);//1.手动添加
                    addUserInfo.set("house_name", voteInfo.getString("community_name"));//小区名称  无意义参数
                    this.publicAdditionsAddOrUpdateVoteUser(addUserInfo);
                }
            }
        }

        if (step_big < 4) {
            //添加文件信息
            CDO heldOwnerCongress = cdoRequest.getCDO("heldOwnerCongress");
            heldOwnerCongress.set("essential_information_id", id);
            heldOwnerCongress.set("user_id", userId);
            voteStatuteImgDao.addVoteStatuteImg(heldOwnerCongress);
            List<CDO> negotiatingTeamList = cdoRequest.getCDOList("negotiatingTeamList");
            for (CDO negotiatingInfo : negotiatingTeamList) {
                String full_name = negotiatingInfo.getString("full_name");
                String telephone = negotiatingInfo.getString("telephone");
                String company = negotiatingInfo.getString("company");
                String teamUserId = this.getUserIdByUserNameAndTel(full_name, telephone);
                negotiatingInfo.set("user_id", teamUserId);
                negotiatingInfo.set("user_id_zyw", userId);
                negotiatingInfo.set("house_name", voteInfo.getString("community_name"));//小区名称  无意义参数
                this.publicAdditionsAddOrUpdateVoteUser(negotiatingInfo);
            }
        }

        if (step_big < 5) {
            CDO selectOrg = new CDO();
            selectOrg.set("p_id", id);
            selectOrg.set("recordFrom", 0);
            selectOrg.set("recordSize", 10);
            List<CDO> orgList = voteOrgInfoDao.getVoteOrgInfoListPage(selectOrg);
            for (CDO orgInfo : orgList) {
                if (orgInfo.getInteger("org_vote_type") == 0) {
                    CDO updateOrg = new CDO();
                    updateOrg.set("id", orgInfo.getString("id"));
                    updateOrg.set("org_vote_type", 1);
                    voteOrgInfoDao.updateVoteOrgInfoById(updateOrg);
                    break;
                }
            }
            String check_org_vote_begin_time = cdoRequest.getString("check_org_vote_begin_time");
            String check_org_vote_end_time = cdoRequest.getString("check_org_vote_end_time");
            CDO updateVoteInfo = new CDO();
            updateVoteInfo.set("id", id);
            updateVoteInfo.set("check_org_vote_begin_time", check_org_vote_begin_time);
            updateVoteInfo.set("check_org_vote_end_time", check_org_vote_end_time);
            voteEssentialInformationDao.updateVoteEssentialInformationById(updateVoteInfo);
        }
        return null;
    }

    /**
     * 校验物业公司表单条件
     *
     * @param orgInfo
     * @return
     */
    public String verifyCheckOrgAddOrgInfo(CDO orgInfo) {
        if (StringUtils.isEmpty(orgInfo.getString("org_name"))) {
            return "请填写物业公司名称";
        }
        if (StringUtils.isEmpty(orgInfo.getString("org_province"))) {
            return "请选择省";
        }
        if (StringUtils.isEmpty(orgInfo.getString("org_city"))) {
            return "请选择市";
        }
        if (StringUtils.isEmpty(orgInfo.getString("org_district"))) {
            return "请选择区/县";
        }
        if (StringUtils.isEmpty(orgInfo.getString("org_social_credit_code"))) {
            return "请填写社会信用代码";
        }
        if (StringUtils.isEmpty(orgInfo.getString("org_license_img"))) {
            return "请上传公司营业执照";
        }
        if (StringUtils.isEmpty(orgInfo.getString("org_aptitude_img"))) {
            return "请选择资质";
        }
        if (StringUtils.isEmpty(orgInfo.getString("org_sys_name"))) {
            return "请填写法人姓名";
        }

        if (StringUtils.isEmpty(orgInfo.getString("org_enroll_fund"))) {
            return "请填写注册资金";
        }
        if (StringUtils.isEmpty(orgInfo.getString("org_type"))) {
            return "请选择企业类型";
        }
        if (StringUtils.isEmpty(orgInfo.getString("org_rank"))) {
            return "请选择资质等级";
        }
        if (StringUtils.isEmpty(orgInfo.getString("org_employee_total"))) {
            return "请填写员工数量";
        }
        if (StringUtils.isEmpty(orgInfo.getString("org_manage_way"))) {
            return "请选择管理模式";
        }
        if (StringUtils.isEmpty(orgInfo.getString("org_pro_total"))) {
            return "请填写项目数量";
        }
        if (StringUtils.isEmpty(orgInfo.getString("org_area_sum"))) {
            return "请填写总面积";
        }
        if (StringUtils.isEmpty(orgInfo.getString("org_pro_type"))) {
            return "请选择在管项目类型";
        }
        return null;
    }

    /**
     * 成立业主大会跳步
     *
     * @param cdoRequest
     * @param voteInfo
     * @return
     */
    public String setUpOwnersMeetingJump(CDO cdoRequest, CDO voteInfo) {
        String id = cdoRequest.getString("id");
        String userId = cdoRequest.getString("userId");
        Integer step_big = cdoRequest.getInteger("step_big");
        Integer step_small = cdoRequest.getInteger("step_small");
        String step_remark = cdoRequest.getString("step_remark");
        //校验筹备组成员信息
        //校验组长是否为助业网用户
        String preparation_name = cdoRequest.getString("preparation_name");
        String preparation_telephone = cdoRequest.getString("preparation_telephone");
        List<CDO> preparationList = cdoRequest.getCDOList("preparationList");
        if (3 < step_big) {
            if (StringUtils.isEmpty(preparation_name)) {
                return "请填写筹备组组长名称";
            }
            if (StringUtils.isEmpty(preparation_telephone)) {
                return "请填写筹备组组长联系电话";
            }
            String preparationUserId = this.getUserIdByUserNameAndTel(preparation_name, preparation_telephone);
            if (StringUtils.isEmpty(preparationUserId)) {
                return "筹备组组长必须是助业网会员";
            }
            cdoRequest.set("preparationUserId", preparationUserId);
            if (preparationList == null) return "请上传筹备组成员信息";
            for (CDO preparationInfo : preparationList) {
                String preparationName = preparationInfo.getString("preparation_name");
                String preparationTelephone = preparationInfo.getString("preparation_telephone");
                String preparationUserId2 = this.getUserIdByUserNameAndTel(preparationName, preparationTelephone);
                if (StringUtils.isEmpty(preparationUserId2)) {
                    return "筹备组成员必须是助业网会员";
                }
                preparationInfo.set("preparationUserId", preparationUserId2);
            }
        }
        //校验上传文件
        //业主规约
        CDO ownerStatute = cdoRequest.getCDO("ownerStatute");
        //议事规则
        CDO rulesOfProcedure = cdoRequest.getCDO("rulesOfProcedure");
        //召开业主大会方案
        CDO heldOwnerCongress = cdoRequest.getCDO("heldOwnerCongress");
        //认证候选委员方案
        CDO certificationCandidateScheme = cdoRequest.getCDO("certificationCandidateScheme");
        //其它文件
        CDO otherFile = cdoRequest.getCDO("otherFile");
        if (4 < step_big) {
            if (ownerStatute == null || rulesOfProcedure == null || heldOwnerCongress == null || certificationCandidateScheme == null) {
                return "请上传文件";
            }
        }
        //校验委员候选人信息
        List<CDO> membersCandidateList = cdoRequest.getCDOList("membersCandidateList");
        if (5 < step_big) {
            if (membersCandidateList == null || membersCandidateList.size() == 0) {
                return "请填写委员候选人信息";
            }
            for (CDO membersInfo : membersCandidateList) {
                String full_name = membersInfo.getString("full_name");
                String telephone = membersInfo.getString("telephone");
                String memberUserId = this.getUserIdByUserNameAndTel(full_name, telephone);
                if (StringUtils.isEmpty(memberUserId)) {
                    return "委员必须是助业网会员";
                }
                membersInfo.set("user_id", memberUserId);
            }
        }
        //添加筹备组信息
        if (3 < step_big) {
            //添加筹备组组长信息
            CDO addLeaderInfo = new CDO();
            addLeaderInfo.set("user_id", cdoRequest.getString("preparationUserId"));
            addLeaderInfo.set("user_id_zyw", cdoRequest.getString("preparationUserId"));
            addLeaderInfo.set("essential_information_id", id);
            addLeaderInfo.set("full_name", preparation_name);
            addLeaderInfo.set("telephone", preparation_telephone);
            addLeaderInfo.set("company", cdoRequest.getString("company"));
            addLeaderInfo.set("preparation_status", 1);//是否筹备组成员：1是，0否
            addLeaderInfo.set("preparation_state", 1);//筹备组：0.成员 1.组长
            addLeaderInfo.set("perparation_add_state", 1);//1.手动添加
            addLeaderInfo.set("house_name", voteInfo.getString("community_name"));//小区名称  无意义参数
            this.publicAdditionsAddOrUpdateVoteUser(addLeaderInfo);
            //添加筹备组成员信息
            for (CDO preparationMemberInfo : preparationList) {
                CDO addUserInfo = new CDO();
                addUserInfo.set("user_id", preparationMemberInfo.getString("preparationUserId"));
                addUserInfo.set("user_id_zyw", preparationMemberInfo.getString("preparationUserId"));
                addUserInfo.set("essential_information_id", id);
                addUserInfo.set("full_name", preparationMemberInfo.getString("preparation_name"));
                addUserInfo.set("telephone", preparationMemberInfo.getString("preparation_telephone"));
                addUserInfo.set("company", preparationMemberInfo.getString("company"));
                addUserInfo.set("preparation_status", 1);//是否筹备组成员：1是，0否
                addUserInfo.set("perparation_add_state", 1);//1.手动添加
                addUserInfo.set("house_name", voteInfo.getString("community_name"));//小区名称  无意义参数
                this.publicAdditionsAddOrUpdateVoteUser(addUserInfo);
            }
            CDO updatePreparationVoteInfo = new CDO();
            updatePreparationVoteInfo.set("id", id);
            updatePreparationVoteInfo.set("preparation_status", 1);
            updatePreparationVoteInfo.set("preparation_vote_user_id", cdoRequest.getString("preparationUserId"));
            updatePreparationVoteInfo.set("preparation_name", preparation_name);
            updatePreparationVoteInfo.set("preparation_telephone", preparation_telephone);
            updatePreparationVoteInfo.set("preparation_company", cdoRequest.getString("company"));
            updatePreparationVoteInfo.set("preparations_number", 1 + preparationList.size());
            voteEssentialInformationDao.updateVoteEssentialInformationById(updatePreparationVoteInfo);
        }
        //添加文件信息
        if (4 < step_big) {
            List<CDO> fileList = new ArrayList<>();
            fileList.add(ownerStatute);
            fileList.add(rulesOfProcedure);
            fileList.add(heldOwnerCongress);
            fileList.add(certificationCandidateScheme);
            if (otherFile != null) {
                fileList.add(otherFile);
            }
            for (CDO fileCDO : fileList) {
                fileCDO.set("essential_information_id", id);
                fileCDO.set("user_id", userId);
                voteStatuteImgDao.addVoteStatuteImg(fileCDO);
            }
        }
        //添加委员候选人信息
        if (5 < step_big) {
            for (CDO membersInfo : membersCandidateList) {
                membersInfo.set("committee_member_status", 1);
                this.publicAdditionsAddOrUpdateVoteUser(membersInfo);
            }
        }
        //修改投票信息
        CDO updateVoteInfo = new CDO();
        updateVoteInfo.set("id", id);
        updateVoteInfo.set("four_owner_publicity_time", cdoRequest.getString("four_owner_publicity_time"));
        updateVoteInfo.set("four_owner_statute_img", cdoRequest.getString("four_owner_statute_img"));
        updateVoteInfo.set("four_deliberation_statute_img", cdoRequest.getString("four_deliberation_statute_img"));
        updateVoteInfo.set("four_owner_programme_img", cdoRequest.getString("four_owner_programme_img"));
        updateVoteInfo.set("four_certification_candidate_img", cdoRequest.getString("four_certification_candidate_img"));
        updateVoteInfo.set("five_recruit", cdoRequest.getString("five_recruit"));
        voteEssentialInformationDao.updateVoteEssentialInformationById(updateVoteInfo);
        //添加跳步信息至vote_jump_step
        CDO addJumpInfo = new CDO();
        addJumpInfo.set("essential_information_id", id);
        addJumpInfo.set("user_id", userId);
        addJumpInfo.set("jump_big_step", step_big);
        addJumpInfo.set("jump_small_step", step_small);
        addJumpInfo.set("owner_meeting_application_form", cdoRequest.getString("owner_meeting_application_form"));
        addJumpInfo.set("owner_meeting_seconded_record", cdoRequest.getString("owner_meeting_seconded_record"));
        addJumpInfo.set("owner_meeting_seconded_number", cdoRequest.getString("owner_meeting_seconded_number"));
        addJumpInfo.set("owner_meeting_seconded_number_ratio", cdoRequest.getString("owner_meeting_seconded_number_ratio"));
        addJumpInfo.set("owner_meeting_seconded_area", cdoRequest.getString("owner_meeting_seconded_area"));
        addJumpInfo.set("owner_meeting_seconded_area_ratio", cdoRequest.getString("owner_meeting_seconded_area_ratio"));
        addJumpInfo.set("owner_meeting_seconded_submit_time", cdoRequest.getString("owner_meeting_seconded_submit_time"));
        voteEssentialInformationDao.addVoteJumpStepInfo(addJumpInfo);
        return null;
    }

    /**
     * 获取线下投票信息
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return getOfflineVotingInfo(CDO cdoRequest) {
        String id = cdoRequest.getString("id");
        if (StringUtils.isEmpty(id)) return Return.valueOf(-2, "表决id不可为空");
        CDO voteInfo = voteEssentialInformationDao.getVoteEssentialInformationById(Integer.parseInt(id));
        if (voteInfo == null) return Return.valueOf(-2, "表决信息异常");
        //线下投票数量
        cdoRequest.set("seven_offline_vote_total", voteInfo.getString("seven_offline_vote_total"));
        //线下投票凭证
        cdoRequest.set("seven_offline_img", voteInfo.getString("seven_offline_img"));
        CDO fileSelect = new CDO();
        fileSelect.set("essential_information_id", id);
        fileSelect.set("statute_state", 1);
        //业主规约
        CDO ownerStatuteInfo = voteStatuteImgDao.getVoteStatuteImg(fileSelect);
        if (ownerStatuteInfo == null) return Return.valueOf(-2, "业主规约信息异常");
        cdoRequest.set("ownerStatuteInfo", ownerStatuteInfo);
        //议事规则
        fileSelect.set("statute_state", 2);
        CDO rulesOfProcedureInfo = voteStatuteImgDao.getVoteStatuteImg(fileSelect);
        if (rulesOfProcedureInfo == null) return Return.valueOf(-2, "议事规则信息异常");
        cdoRequest.set("rulesOfProcedureInfo", rulesOfProcedureInfo);
        //人员集合
        CDO selectUser = new CDO();
        selectUser.set("essential_information_id", id);
        selectUser.set("committee_member_status", 1);
        List<CDO> voteUserList = voteEssentialInformationDao.getVoteUserListByCDO(selectUser);
        cdoRequest.set("voteUserList", voteUserList);
        List<CDO> alreadyUserList = new ArrayList<>();
        for (CDO userInfo : voteUserList) {
            String committee_member_total_offline = userInfo.getString("committee_member_total_offline");
            committee_member_total_offline = StringUtils.isEmpty(committee_member_total_offline) ? "0" : committee_member_total_offline;
            if (!committee_member_total_offline.equals("0")) {
                alreadyUserList.add(userInfo);
            }
        }
        cdoRequest.set("alreadyUserList", alreadyUserList);
        return Return.valueOf(cdoRequest);
    }

    /**
     * 第七步添加或修改线下投票
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return sevenUpdateOfflineVoting(CDO cdoRequest) {
        String id = cdoRequest.getString("id");//表决id
        if (StringUtils.isEmpty(id)) return Return.valueOf(-2, "表决id不可为空");
        //线下投票人数
        String seven_offline_vote_total = cdoRequest.getString("seven_offline_vote_total");
        if (StringUtils.isEmpty(seven_offline_vote_total))
            return Return.valueOf(-2, "线下投票人数seven_offline_vote_total不可为空");
        //业主规约 id
        String ownerStatuteId = cdoRequest.getString("ownerStatuteId");
        if (StringUtils.isEmpty(ownerStatuteId)) return Return.valueOf(-2, "业主规约ownerStatuteId不可为空");
        String ownerAddTotal = cdoRequest.getString("ownerAddTotal");
        if (StringUtils.isEmpty(ownerAddTotal)) return Return.valueOf(-2, "业主规约添加数量ownerAddTotal不可为空");
        //议事规则 id
        String rulesOfProcedureId = cdoRequest.getString("rulesOfProcedureId");
        if (StringUtils.isEmpty(rulesOfProcedureId)) return Return.valueOf(-2, "议事规则rulesOfProcedureId不可为空");
        String rulesAddTotal = cdoRequest.getString("rulesAddTotal");
        if (StringUtils.isEmpty(rulesAddTotal)) return Return.valueOf(-2, "议事规则添加数量rulesAddTotal不可为空");
        //线下凭证
        String seven_offline_img = cdoRequest.getString("seven_offline_img");
        if (StringUtils.isEmpty(seven_offline_img)) return Return.valueOf(-2, "线下图片凭证seven_offline_img不可为空");
        List<CDO> peopleList = cdoRequest.getCDOList("peopleList");
        if (peopleList == null) return Return.valueOf(-2, "peopleList不可为空");
        CDO updateVoteInfo = new CDO();
        updateVoteInfo.set("id", id);
        updateVoteInfo.set("seven_offline_vote_total", seven_offline_vote_total);
        updateVoteInfo.set("seven_offline_img", seven_offline_img);
        voteEssentialInformationDao.updateVoteEssentialInformationById(updateVoteInfo);
        CDO updateFileOne = new CDO();
        updateFileOne.set("id", ownerStatuteId);
        updateFileOne.set("offline_agree_total", ownerAddTotal);
        voteStatuteImgDao.updateVoteStatuteImgById(updateFileOne);
        CDO updateFileTwo = new CDO();
        updateFileTwo.set("id", rulesOfProcedureId);
        updateFileTwo.set("offline_agree_total", rulesAddTotal);
        voteStatuteImgDao.updateVoteStatuteImgById(updateFileTwo);
        //先将所有的候选人线下图片改为0，再依次修改用户填写的票数
        CDO updateUserAll = new CDO();
        updateUserAll.set("essential_information_id", id);
        updateUserAll.set("committee_member_total_offline", 0);
        voteUserDao.updateVoteUserById(updateUserAll);
        for (CDO userInfo : peopleList) {
            String userVoteId = userInfo.getString("id");
            String committee_member_total_offline = userInfo.getString("committee_member_total_offline");
            if (!StringUtils.isEmpty(id) && !StringUtils.isEmpty(committee_member_total_offline)) {
                CDO updateUserInfo = new CDO();
                updateUserInfo.set("id", userVoteId);
                updateUserInfo.set("committee_member_total_offline", committee_member_total_offline);
                voteUserDao.updateVoteUserById(updateUserInfo);
            }
        }
        return Return.SUCCESS;
    }

    /**
     * 删除文件信息
     *
     * @return
     */
    @OpenApi
    public Return delFileInfoById(CDO cdoRequest) {
        String id = cdoRequest.getString("id");
        if (StringUtils.isEmpty(id)) return Return.valueOf(-2, "文件id不可为空");
        int i = voteStatuteImgDao.deleteVoteStatuteImgById(Integer.parseInt(id));
        return Return.SUCCESS;
    }

    /**
     * 业主端获取统计数据
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return ownerAppGetStatisticsInfoById(CDO cdoRequest) {
        String id = cdoRequest.getString("id");
        if (StringUtils.isEmpty(id)) return Return.valueOf(-2, "表决id不可为空");
        CDO voteInfo = voteEssentialInformationDao.getVoteEssentialInformationById(Integer.parseInt(id));
        if (voteInfo == null) return Return.valueOf(-2, "voteInfo不可为空");
        CDO selectFile = new CDO();
        selectFile.set("essential_information_id", id);
        selectFile.set("record_type", 1);
        selectFile.set("statisticsSelect", 1);//标识参数，只查询业主规约，议事规则
        Integer allTotal = voteVotingRecordsDao.getVoteVotingRecordsCount(selectFile);//业主端参与数量
        allTotal = allTotal != null ? allTotal : 0;
        //线下投票数量
        Integer seven_offline_vote_total = voteInfo.getInteger("seven_offline_vote_total");
        seven_offline_vote_total = seven_offline_vote_total == null ? 0 : seven_offline_vote_total;
        allTotal = allTotal + seven_offline_vote_total;
        selectFile.set("record_state", 1);
        Integer agreeTotal = voteVotingRecordsDao.getVoteVotingRecordsCount(selectFile);//同意数量
        agreeTotal = agreeTotal != null ? agreeTotal : 0;
        //线下文件投票成功数量
        CDO fileSelect = new CDO();
        fileSelect.set("essential_information_id", id);
        fileSelect.set("statute_state", 1);
        //业主规约
        CDO ownerStatuteInfo = voteStatuteImgDao.getVoteStatuteImg(fileSelect);
        if (ownerStatuteInfo != null) {
            Integer offline_agree_total = ownerStatuteInfo.getInteger("offline_agree_total");
            offline_agree_total = offline_agree_total == null ? 0 : offline_agree_total;
            agreeTotal = agreeTotal + offline_agree_total;
        }
        //议事规则
        fileSelect.set("statute_state", 2);
        CDO rulesOfProcedureInfo = voteStatuteImgDao.getVoteStatuteImg(fileSelect);
        if (rulesOfProcedureInfo != null) {
            Integer offline_agree_total = rulesOfProcedureInfo.getInteger("offline_agree_total");
            offline_agree_total = offline_agree_total == null ? 0 : offline_agree_total;
            agreeTotal = agreeTotal + offline_agree_total;
        }
        Integer passState = 0;//0.通过 1.不通过
        selectFile.set("record_state", 2);
        Integer refuseTotal = voteVotingRecordsDao.getVoteVotingRecordsCount(selectFile);//拒绝数量
        refuseTotal = refuseTotal != null ? refuseTotal : 0;
        Integer household_total = voteInfo.getInteger("household_total");//总户数
        Double community_areass = voteInfo.getDouble("community_areass");//总面积
        List<CDO> resultList = new ArrayList<>();//图表集合
        List<CDO> textList = new ArrayList<>();//文字集合
        int total = 5;
        CDO resultCDO;
        for (int i = 0; i < total; i++) {
            resultCDO = new CDO();//第二层对象
            List<CDO> threeList = new ArrayList<>();//第三层集合
            List<CDO> fourList = new ArrayList<>();//第四层集合
            String ratioStr = null;//比例
            String showRemark = null;//比例下方展示信息
            List<CDO> lastList = new ArrayList<>();//最底层集合
            CDO lastInfo = new CDO();
            CDO lastInfo2 = new CDO();
            if (i == 0) {
                lastInfo.set("name", "参与人数");
                lastInfo.set("value", allTotal);
                lastList.add(lastInfo);
                lastInfo2.set("name", "同意人数");
                lastInfo2.set("value", agreeTotal);
                lastList.add(lastInfo2);
                showRemark = "同意人数" + agreeTotal + "人";
                Double number = Double.parseDouble(agreeTotal.toString()) / allTotal * 100;
                if (number < 50) passState = 1;
                ratioStr = this.getDoubleString(number) + "%";
            } else if (i == 1) {
                lastInfo.set("name", "总人数");
                lastInfo.set("value", household_total);
                lastList.add(lastInfo);
                lastInfo2.set("name", "参与人数");
                lastInfo2.set("value", allTotal);
                lastList.add(lastInfo2);
                showRemark = "参与人数" + allTotal + "人";
                Double number = Double.parseDouble(allTotal.toString()) / household_total * 100;
                if (number < 66.66) passState = 1;
                ratioStr = this.getDoubleString(number) + "%";
            } else if (i == 2) {
                lastInfo.set("name", "总面积");
                lastInfo.set("value", community_areass);
                lastList.add(lastInfo);
                lastInfo2.set("name", "参与面积");
                CDO selectArea = new CDO();
                selectArea.set("essential_information_id", id);
                selectArea.set("selectFile", 1);
                Double participateArea = voteVotingRecordsDao.getAreaSumByCDO(selectArea);
                participateArea = participateArea != null ? participateArea : 0;
                lastInfo2.set("value", participateArea);
                lastList.add(lastInfo2);
                showRemark = "参与面积" + participateArea + "平方米";
                ratioStr = this.getDoubleString(participateArea / community_areass * 100) + "%";
            } else if (i == 3) {
                lastInfo.set("name", "同意人数");
                lastInfo.set("value", agreeTotal);
                lastList.add(lastInfo);
                lastInfo2.set("name", "参与人数");
                lastInfo2.set("value", agreeTotal + refuseTotal);
                lastList.add(lastInfo2);
                showRemark = "同意人数占参与人数比率";
                ratioStr = this.getDoubleString(Double.parseDouble(agreeTotal.toString()) / agreeTotal + refuseTotal * 100) + "%";
            } else if (i == 4) {
                CDO selectArea = new CDO();
                selectArea.set("essential_information_id", id);
                selectArea.set("selectFile", 1);
                Double participateArea = voteVotingRecordsDao.getAreaSumByCDO(selectArea);
                participateArea = participateArea != null ? participateArea : 0;//参与面积
                selectArea.set("record_state", 1);
                Double agreeArea = voteVotingRecordsDao.getAreaSumByCDO(selectArea);
                agreeArea = agreeArea != null ? agreeArea : 0;//同意面积
                lastInfo.set("name", "同意面积");
                lastInfo.set("value", agreeArea);
                lastList.add(lastInfo);
                lastInfo2.set("name", "参与面积");
                lastInfo2.set("value", participateArea);
                lastList.add(lastInfo2);
                showRemark = "同意面积占参与面积比率";
                ratioStr = this.getDoubleString(agreeArea / participateArea * 100) + "%";
            }
            CDO lastCdo = new CDO();
            lastCdo.set("data", lastList);
            List<CDO> lastList2 = new ArrayList<>();
            lastList2.add(lastCdo);
            CDO lastCdo3 = new CDO();
            lastCdo3.set("series", lastList2);
            resultList.add(lastCdo3);
            CDO showText = new CDO();
            showText.set("ratioStr", ratioStr);
            showText.set("showRemark", showRemark);
            textList.add(showText);
        }
        CDO result = new CDO();
        result.set("textList", textList);
        result.set("resultList", resultList);
        result.set("passState", passState);
        //通过条件，2/3人参与  同意人数展示参与人数 1/2
        return Return.valueOf(result);
    }


    /**
     * 解聘物业，事项同意记录
     *
     * @return
     */
    @OpenApi
    public Return getThinsUserList(CDO cdoRequest) {
        String essential_information_id = cdoRequest.getString("essential_information_id");
        if (StringUtils.isEmpty(essential_information_id)) {
            return Return.valueOf(-2, "essential_information_id不可为空");
        }
        Integer pageIndex = cdoRequest.getInteger("pageIndex") - 1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> userThingList = voteEssentialInformationDao.getThingsUserListPage(cdoRequest);
        boolean isEndPage = false;
        if (userThingList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", userThingList);
        int total = voteEssentialInformationDao.getThingsUserListTotal(cdoRequest);
        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }

    /**
     * 获取议题统计集合
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return getThingsStatics(CDO cdoRequest) {
        String essential_information_id = cdoRequest.getString("essential_information_id");
        if (StringUtils.isEmpty(essential_information_id)) {
            return Return.valueOf(-2, "essential_information_id不可为空");
        }
        CDO voteInfo = voteEssentialInformationDao.getVoteEssentialInformationById(Integer.parseInt(essential_information_id));
        if (voteInfo == null) {
            return Return.valueOf(-2, "表决信息异常");
        }
        //小区面积
        Double community_areass = voteInfo.getDouble("community_areass");
        //小区户数
        Double household_total = voteInfo.getDouble("household_total");
        //通过面积，通过户数
        long passArea = Math.round(community_areass * 2 / 3);
        long passHouse = Math.round(household_total * 2 / 3);
        //本次参与户数
        CDO selectInvolved = new CDO();
        selectInvolved.set("essential_information_id", essential_information_id);
        Integer involvedTotal = voteEssentialInformationDao.getThingsInvolvedTotal(selectInvolved);
        CDO selectThings = new CDO();
        selectThings.set("essential_information_id", essential_information_id);
        selectThings.set("statute_state", 6);
        //议题，2/3参与，1/2同意
        List<CDO> thingsList = voteStatuteImgDao.getVoteStatuteImgList(selectThings);
        //0.可通过 1.不可通过
        Integer whetherCanPass = 0;
        for (CDO thingsInfo : thingsList) {
            String id = thingsInfo.getString("id");
            CDO selectFile = new CDO();
            selectFile.set("statute_id", id);
            Integer agreeTotal = voteVotingRecordsDao.getVoteVotingRecordsCount(selectFile);
            //参与数量
            thingsInfo.set("attendTotal", involvedTotal);
            //比例
            Double houseNumber = Double.parseDouble(involvedTotal + "") / Double.parseDouble(household_total + "") * 100;
            if (houseNumber < 66.6 && whetherCanPass == 0) {
                whetherCanPass = 1;
            }
            thingsInfo.set("houseRatio", this.getDoubleString(houseNumber) + "%");
            //通过所需户数
            thingsInfo.set("passHouse", passHouse);
            //已收集户数
            thingsInfo.set("agreeHouse", agreeTotal);
            //已收集户数比例
            Double roomDouble = Double.parseDouble(agreeTotal + "") / Double.parseDouble(involvedTotal + "") * 100;
            if (roomDouble < 50 && whetherCanPass == 0) {
                whetherCanPass = 1;
            }
            thingsInfo.set("agreeHouseRatio", this.getDoubleString(roomDouble) + "%");
            //通过所需面积
            thingsInfo.set("passArea", passArea);
            //已收集面积
            CDO selectArea = new CDO();
            selectArea.set("essential_information_id", essential_information_id);
            selectArea.set("thing_id", id);
            selectArea.set("selectThing", 1);
            Double participateArea = voteVotingRecordsDao.getAreaSumByCDO(selectArea);
            participateArea = participateArea != null ? participateArea : 0;
            thingsInfo.set("agreeArea", participateArea);
            //已收集面积比例
            thingsInfo.set("agreeAreaRatio", this.getDoubleString(participateArea / community_areass * 100) + "%");
        }
        CDO resultCdo = new CDO();
        resultCdo.set("thingsList", thingsList);
        resultCdo.set("whetherCanPass", whetherCanPass);
        return Return.valueOf(resultCdo);
    }

    @OpenApi
    public Return addVoteRedSelectInfo(CDO cdoRequest) {
        String p_id = cdoRequest.getString("p_id");
        String user_id = cdoRequest.getString("user_id");
        if (StringUtils.isEmpty(p_id)) return Return.valueOf(-2, "记录p_id不可为空");
        if (StringUtils.isEmpty(user_id)) return Return.valueOf(-2, "操作人user_id不可为空");
        int redTotal = voteEssentialInformationDao.getRedTotalByCDO(cdoRequest);
        if (redTotal > 0) return Return.valueOf(0);
        voteEssentialInformationDao.addVoteDotsRecordInfo(cdoRequest);
        return Return.valueOf(1);
    }

    /**
     * 业主端绑定用户与投票基本信息
     *
     * @return
     */
    @OpenApi
    public Return bindUserAndVoteInfo(CDO cdoRequest) {
        String user_id = cdoRequest.getString("user_id");
        if (StringUtils.isEmpty(user_id)) return Return.valueOf(-2, "user_id不可为空");
        String essential_information_id = cdoRequest.getString("essential_information_id");
        if (StringUtils.isEmpty(essential_information_id)) return Return.valueOf(-2, "essential_information_id不可为空");
        CDO select = new CDO();
        select.set("user_id", user_id);
        select.set("essential_information_id", essential_information_id);
        int voteUserCount = voteUserDao.getVoteUserListCount(select);
        if (voteUserCount > 0) {
            return Return.valueOf("已有数据，无需绑定");
        }
        voteUserDao.addVoteUser(cdoRequest);
        return Return.valueOf("基本认证信息绑定成功！");
    }

    /**
     * 根据项目名称获取项目集合
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return getProNameListByProName(CDO cdoRequest) {
        String pro_name = cdoRequest.getString("pro_name");
        if (StringUtils.isEmpty(pro_name)) return Return.valueOf(-2, "pro_name项目名称不可为空");
        //查询物业后台项目
        List<CDO> proList = voteEssentialInformationDao.getProListByProName(pro_name);
        return Return.valueOf(proList);
    }

    /**
     * 校验该项目是否已经在投票中
     *
     * @return
     */
    @OpenApi
    public Return verifyVoteProByName(CDO cdoRequest) {
        String pro_name = cdoRequest.getString("pro_name");
        if (StringUtils.isEmpty(pro_name)) return Return.valueOf(-2, "pro_name项目名称不可为空");
        //返回回个对象
        CDO voteInfo = voteEssentialInformationDao.verifyVoteProByProName(pro_name);
        return Return.valueOf(voteInfo);
    }

    /**
     * 业主app获取投票记录
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return getOwnerAppVoteRecordList(CDO cdoRequest) {
        List<CDO> voteRecommendList = voteEssentialInformationDao.getOwnerAppVoteRecordListByCDO(cdoRequest);
        return Return.valueOf(voteRecommendList);
    }


    /**
     * 业主app首页获取投票图标红点信息
     *
     * @return
     */
    @OpenApi
    public Return getVoteRedDotsInfoByHome(CDO cdoRequest) {
        String userId = cdoRequest.getString("userId");
        //表决id，按业务场景传值
        String voteId = cdoRequest.getString("voteId");
        if (StringUtils.isEmpty(userId)) return Return.valueOf(-2, "userId不可为空");
        cdoRequest.set("redDotsTotal", this.getRedDotsTotal(userId, voteId));
        return Return.valueOf(cdoRequest);
    }

    public Integer getRedDotsTotal(String userId, String voteId) {
        if (StringUtils.isEmpty(userId)) {
            return 0;
        }
        //查询该userId所处表决是否有投票或公示的信息
        return voteEssentialInformationDao.getRedDotsInfoByUserIdAndVoteId(userId, voteId);
    }

    /**
     * 获取压缩包所需信息
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return getZipInfoById(CDO cdoRequest) {
        String id = cdoRequest.getString("id");
        if (StringUtils.isEmpty(id)) return Return.valueOf(-2, "表决id不可为空");
        //申请书、备案单---未知

        //文件
        //议事规则
        cdoRequest.set("rulesOfProcedureFile", voteEssentialInformationDao.getFileInfoByIdAndId(2, id));
        //业主规约
        cdoRequest.set("ownerStatuteFile", voteEssentialInformationDao.getFileInfoByIdAndId(1, id));
        //会议方案
        cdoRequest.set("meetingScenariosFile", voteEssentialInformationDao.getFileInfoByIdAndId(3, id));

        //业主大会决议----未知

        //委员身份信息
        CDO selectMembers = new CDO();
        selectMembers.set("selectCommitteePositions", 1);
        selectMembers.set("essential_information_id", id);
        cdoRequest.set("membersList", voteEssentialInformationDao.getVoteUserListByCDO(selectMembers));
        return Return.valueOf(cdoRequest);
    }

    /**
     * 第9步，结束按钮
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return nineEndClickComplete(CDO cdoRequest) {
        String userId = cdoRequest.getString("userId");
        String id = cdoRequest.getString("id");
        if (StringUtils.isEmpty(id)) return Return.valueOf(-2, "表决id不可为空");
        CDO voteInfo = voteEssentialInformationDao.getVoteEssentialInformationById(Integer.parseInt(id));
        if (voteInfo == null) return Return.valueOf(-2, "表决信息异常");
        //备案状态 1.成功 2.失败
        Integer nine_record_state = cdoRequest.getInteger("nine_record_state");
        if (nine_record_state == null) return Return.valueOf(-2, "备案状态nine_record_state不可为空");
        String nine_filing_form = cdoRequest.getString("nine_filing_form");//备案单
        String nine_disband_notice = cdoRequest.getString("nine_disband_notice");//解散公告
        String nine_overrule_img = cdoRequest.getString("nine_overrule_img");//驳回证明
        String nine_overrule = cdoRequest.getString("nine_overrule");//驳回理由
        CDO updateVote = new CDO();
        updateVote.set("id", id);
        updateVote.set("nine_record_state", nine_record_state);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        updateVote.set("nine_record_time", sdf.format(new Date()));
        if (nine_record_state == 1) {
            if (StringUtils.isEmpty(nine_filing_form)) return Return.valueOf(-2, "请上传备案单");
            if (StringUtils.isEmpty(nine_disband_notice)) return Return.valueOf(-2, "请上传备案单筹备组解散公告");
            updateVote.set("nine_filing_form", nine_filing_form);
            updateVote.set("nine_disband_notice", nine_disband_notice);
        } else {
            if (StringUtils.isEmpty(nine_overrule_img)) return Return.valueOf(-2, "请上传驳回证明");
            if (StringUtils.isEmpty(nine_overrule)) return Return.valueOf(-2, "请填写驳回理由");
            updateVote.set("nine_overrule_img", nine_overrule_img);
            updateVote.set("nine_overrule", nine_overrule);
        }
        voteEssentialInformationDao.updateVoteEssentialInformationById(updateVote);
        //添加步骤
        CDO addVoteStep = new CDO();
        addVoteStep.set("step_id", id);
        addVoteStep.set("user_id", userId);
        addVoteStep.set("property", voteInfo.getString("community_name"));
        //数据备注
        addVoteStep.set("planned_speed", "上传备案结果");
        addVoteStep.set("complete_state", 1);
        //到第几大步
        addVoteStep.set("step_big", 9);
        //到第几小步
        addVoteStep.set("step_small", 3);
        this.publicAdditionsAddVoteStep(addVoteStep);

        return Return.SUCCESS;
    }

    /**
     * 第九步，上传回执
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return nineStepClickComplete(CDO cdoRequest) {
        String userId = cdoRequest.getString("userId");
        String nine_submit_time = cdoRequest.getString("nine_submit_time");
        if (StringUtils.isEmpty(nine_submit_time)) return Return.valueOf(-2, "请选择回执时间");
        String nine_upload_prove_img = cdoRequest.getString("nine_upload_prove_img");
        if (StringUtils.isEmpty(nine_submit_time)) return Return.valueOf(-2, "请上创回执图片");
        String id = cdoRequest.getString("id");
        if (StringUtils.isEmpty(id)) return Return.valueOf(-2, "表决id不可为空");
        CDO voteInfo = voteEssentialInformationDao.getVoteEssentialInformationById(Integer.parseInt(id));
        if (voteInfo == null) return Return.valueOf(-2, "表决信息异常");
        CDO updateVoteInfo = new CDO();
        updateVoteInfo.set("id", id);
        updateVoteInfo.set("nine_submit_time", nine_submit_time);
        updateVoteInfo.set("nine_upload_prove_img", nine_upload_prove_img);
        voteEssentialInformationDao.updateVoteEssentialInformationById(updateVoteInfo);
        //添加步骤
        CDO addVoteStep = new CDO();
        addVoteStep.set("step_id", id);
        addVoteStep.set("user_id", userId);
        addVoteStep.set("property", voteInfo.getString("community_name"));
        //数据备注
        addVoteStep.set("planned_speed", "上传回执并点击确定");
        addVoteStep.set("complete_state", 1);
        //到第几大步
        addVoteStep.set("step_big", 9);
        //到第几小步
        addVoteStep.set("step_small", 2);
        this.publicAdditionsAddVoteStep(addVoteStep);
        return Return.SUCCESS;
    }

    /**
     * 第8步点击继续前往第9步
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return eightGoToNine(CDO cdoRequest) {
        String id = cdoRequest.getString("id");
        if (StringUtils.isEmpty(id)) return Return.valueOf(-2, "表决id不可为空");
        String userId = cdoRequest.getString("userId");
        CDO voteInfo = voteEssentialInformationDao.getVoteEssentialInformationById(Integer.parseInt(id));
        if (voteInfo == null) return Return.valueOf(-2, "表决信息异常");
        //修改业委会职位公示结束
        CDO record = new CDO();
        record.set("essential_information_id", id);
        record.set("vote_type", 12);
        CDO recordInfo = voteRecordDao.getVoteRecordByCdo(record);
        if (recordInfo != null) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            CDO updateRecord = new CDO();
            updateRecord.set("id", recordInfo.getString("id"));
            updateRecord.set("update_time", sdf.format(new Date()));
            updateRecord.set("vote_state", 1);//1.结束 0.进行中
            voteRecordDao.updateVoteRecordById(updateRecord);
        }
        //添加步骤
        CDO addVoteStep = new CDO();
        addVoteStep.set("step_id", id);
        addVoteStep.set("user_id", userId);
        addVoteStep.set("property", voteInfo.getString("community_name"));
        //数据备注
        addVoteStep.set("planned_speed", "业委会职位公示结束点击继续");
        addVoteStep.set("complete_state", 1);
        //到第几大步
        addVoteStep.set("step_big", 9);
        //到第几小步
        addVoteStep.set("step_small", 1);
        this.publicAdditionsAddVoteStep(addVoteStep);
        return Return.SUCCESS;
    }


    /**
     * 确认主任副主任
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return confirmTheDirectorInfo(CDO cdoRequest) {
        String id = cdoRequest.getString("id");
        if (StringUtils.isEmpty(id)) return Return.valueOf(-2, "表决id不可为空");
        String userId = cdoRequest.getString("userId");
        //发布类型 1.主任 2.副主任
        Integer launchType = cdoRequest.getInteger("launchType");
        if (launchType == null) return Return.valueOf(-2, "发布类型launchType不可为空");
        CDO voteInfo = voteEssentialInformationDao.getVoteEssentialInformationById(Integer.parseInt(id));
        if (voteInfo == null) return Return.valueOf(-2, "表决信息异常");
        //修改委员投票结束
        CDO record = new CDO();
        record.set("essential_information_id", id);
        record.set("vote_type", launchType == 1 ? 10 : 11);
        //委员投票活动
        CDO recordInfo = voteRecordDao.getVoteRecordByCdo(record);
        if (recordInfo != null) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            CDO updateRecord = new CDO();
            updateRecord.set("id", recordInfo.getString("id"));
            updateRecord.set("update_time", sdf.format(new Date()));
            updateRecord.set("vote_state", 1);//1.结束 0.进行中
            voteRecordDao.updateVoteRecordById(updateRecord);
        }
        CDO selectUser = new CDO();
        selectUser.set("essential_information_id", id);
        selectUser.set("members_state", 1);
        String selectResult = launchType == 1 ? "directorOrder" : "deputyDirectorOrder";
        selectUser.set(selectResult, 1);//标识参数，按主任||副主任票数排序
        List<CDO> voteUserList = voteEssentialInformationDao.getVoteUserListByCDO(selectUser);
        Integer total = launchType == 1 ? voteInfo.getInteger("four_directors__number") : voteInfo.getInteger("four_deputy_directors__number");
        String updateStr = launchType == 1 ? "director" : "deputy_director";
        for (int i = 0; i < voteUserList.size(); i++) {
            CDO voteUserInfo = voteUserList.get(i);
            if (i + 1 <= total) {
                //修改该人为主任或副主任
                CDO updateUser = new CDO();
                updateUser.set("id", voteUserInfo.getString("id"));
                updateUser.set(updateStr, 1);
                voteUserDao.updateUserInfoByCDO(updateUser);
            }
        }
        //添加步骤
        CDO addVoteStep = new CDO();
        addVoteStep.set("step_id", id);
        addVoteStep.set("user_id", userId);
        addVoteStep.set("property", voteInfo.getString("community_name"));
        //数据备注
        addVoteStep.set("planned_speed", launchType == 1 ? "确认主任信息" : "确认副主任信息");
        addVoteStep.set("complete_state", 1);
        //到第几大步
        addVoteStep.set("step_big", 8);
        //到第几小步
        addVoteStep.set("step_small", launchType == 1 ? 3 : 4);
        this.publicAdditionsAddVoteStep(addVoteStep);

        if (launchType == 2) {
            //确认副主任，添加业委会主任职位结果公示
            CDO addVote = new CDO();
            addVote.set("user_id", userId);
            addVote.set("essential_information_id", id);
            addVote.set("vote_name", "业委会职位结果公示");
            addVote.set("vote_type", 12);//业委会职位结果公示
            this.addVoteRecord(addVote);
        }

        return Return.SUCCESS;
    }

    /**
     * 获取主任投票记录
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return getDirectorVoteRecord(CDO cdoRequest) {
        String essential_information_id = cdoRequest.getString("essential_information_id");
        Integer launchType = cdoRequest.getInteger("launchType");
        if (StringUtils.isEmpty(essential_information_id)) return Return.valueOf(-2, "表决essential_information_id不可为空");
        if (launchType == null) return Return.valueOf(-2, "launchType不可为空");
        CDO voteInfo = voteEssentialInformationDao.getVoteEssentialInformationById(Integer.parseInt(essential_information_id));
        if (voteInfo == null) return Return.valueOf(-2, "表决信息异常");
        //委员人数
        Integer four_members_number = voteInfo.getInteger("four_members_number");
        four_members_number = four_members_number != null ? four_members_number : 0;
        List<CDO> voteRecordList = voteRecordDao.getVoteRecordList(cdoRequest);
        for (int i = 0; i < voteRecordList.size(); i++) {
            CDO recordInfo = voteRecordList.get(i);
            String vote_user_director_info = recordInfo.getString("vote_user_director_info");
            if (!StringUtils.isEmpty(vote_user_director_info)) {
                recordInfo.set("voteResult", CDO.parse(vote_user_director_info));
                //2023-2-9，数据库未存贮历史记录的已投，未投数量，可以在 vote_record 表新增这俩字段，重新发起投票将信息存贮
                //已投人数
                recordInfo.set("castTotal", "作废");
                //未投票人数     委员数量 - 已投人数
                recordInfo.set("notCastTotal", "作废");
            } else {
                //最新的投票结果
                CDO selectUser = new CDO();
                selectUser.set("essential_information_id", essential_information_id);
                selectUser.set("members_state", 1);
                String selectResult = launchType == 1 ? "directorOrder" : "deputyDirectorOrder";
                selectUser.set(selectResult, 1);//标识参数，按主任||副主任票数排序
                recordInfo.set("voteResult", voteEssentialInformationDao.getVoteUserListByCDO(selectUser));
                CDO verifyVote = new CDO();
                verifyVote.set("essential_information_id", essential_information_id);
                verifyVote.set("recommend_state", launchType == 1 ? 4 : 5);
                verifyVote.set("state", 0);
                Integer voteTotal = voteEssentialInformationDao.getVoteUserRecordListByCDOTotal(verifyVote);
                voteTotal = voteTotal == null ? 0 : voteTotal;
                //已投人数
                recordInfo.set("castTotal", voteTotal);
                //未投票人数     委员数量 - 已投人数
                recordInfo.set("notCastTotal", four_members_number - voteTotal);
            }
        }
        return Return.valueOf(voteRecordList);
    }

    /**
     * 发起主任投票
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return launchDirectorVote(CDO cdoRequest) {
        String id = cdoRequest.getString("id");
        if (StringUtils.isEmpty(id)) return Return.valueOf(-2, "表决id不可为空");
        String userId = cdoRequest.getString("userId");
        //发布类型 1.主任 2.副主任
        Integer launchType = cdoRequest.getInteger("launchType");
        if (launchType == null) Return.valueOf(-2, "发布类型launchType不可为空");
        CDO voteInfo = voteEssentialInformationDao.getVoteEssentialInformationById(Integer.parseInt(id));
        if (voteInfo == null) return Return.valueOf(-2, "表决信息异常");
        String end_time = cdoRequest.getString("end_time");
        if (StringUtils.isEmpty(end_time)) return Return.valueOf(-2, "结束时间end_time不可为空");
        //查询投票记录，将投票结果存贮至公示记录表
        CDO selectRecord = new CDO();
        selectRecord.set("essential_information_id", id);
        selectRecord.set("vote_type", launchType == 1 ? 10 : 11);
        List<CDO> voteRecordList = voteRecordDao.getVoteRecordList(selectRecord);
        //修改表决表，记录结束时间
        //2023-1-17，结束时间改为开始时间，字段名不变
        CDO updateVote = new CDO();
        updateVote.set("id", id);
        updateVote.set("eight_director_time", end_time);
        voteEssentialInformationDao.updateVoteEssentialInformationById(updateVote);
        //修改已投票记录，数据状态为删除
        CDO updateVoteRecord = new CDO();
        updateVoteRecord.set("essential_information_id", id);
        updateVoteRecord.set("recommend_state", launchType == 1 ? 4 : 5);
        voteEssentialInformationDao.updateVoteRecord(updateVoteRecord);
        //添加公示信息
        CDO addVote = new CDO();
        addVote.set("user_id", userId);
        addVote.set("essential_information_id", id);
        addVote.set("vote_end_time", end_time);
        addVote.set("vote_name", launchType == 1 ? "第" + (voteRecordList.size() + 1) + "次主任投票公示"
                : "第" + (voteRecordList.size() + 1) + "次副主任投票公示");
        addVote.set("vote_type", launchType == 1 ? 10 : 11);//10.主任投票 11.副主任投票
        if (voteRecordList.size() > 0) {
            //将最新的投票结果存贮至最新的公示记录，并将用户表主任票数清0
            CDO selectUser = new CDO();
            selectUser.set("essential_information_id", id);
            selectUser.set("members_state", 1);
            String selectResult = launchType == 1 ? "directorOrder" : "deputyDirectorOrder";
            selectUser.set(selectResult, 1);//标识参数，按主任||副主任票数排序
            List<CDO> voteUserList = voteEssentialInformationDao.getVoteUserListByCDO(selectUser);
            CDO updateRecord = new CDO();
            updateRecord.set("id", voteRecordList.get(0).getString("id"));
            updateRecord.set("vote_user_director_info", voteUserList.toString());
            updateRecord.set("vote_state", 1);
            voteRecordDao.updateVoteRecordById(updateRecord);
            for (CDO userVoteInfo : voteUserList) {
                CDO updateUserInfo = new CDO();
                updateUserInfo.set("id", userVoteInfo.getString("id"));
                if (launchType == 1) {
                    //主任
                    updateUserInfo.set("director_vote_total", 0);
                } else {
                    //副主任
                    updateUserInfo.set("deputy_director_vote_total", 0);
                }
                voteUserDao.updateUserInfoByCDO(updateUserInfo);
            }
        }
        this.addVoteRecord(addVote);
        //添加步骤
        CDO addVoteStep = new CDO();
        addVoteStep.set("step_id", id);
        addVoteStep.set("user_id", userId);
        addVoteStep.set("property", voteInfo.getString("community_name"));
        //数据备注
        addVoteStep.set("planned_speed", launchType == 1 ? "发起主任投票" : "发起副主任投票");
        addVoteStep.set("complete_state", 1);
        //到第几大步
        addVoteStep.set("step_big", 8);
        //到第几小步
        addVoteStep.set("step_small", launchType == 1 ? 2 : 4);
        this.publicAdditionsAddVoteStep(addVoteStep);
        return Return.SUCCESS;
    }


    /**
     * 第7步，点击继续
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return sevenGoToNext(CDO cdoRequest) {
        String id = cdoRequest.getString("id");
        if (StringUtils.isEmpty(id)) return Return.valueOf(-2, "表决id不可为空");
        String userId = cdoRequest.getString("userId");
        CDO voteInfo = voteEssentialInformationDao.getVoteEssentialInformationById(Integer.parseInt(id));
        if (voteInfo == null) return Return.valueOf(-2, "表决信息异常");
        String record_id = cdoRequest.getString("record_id");
        if (StringUtils.isEmpty(record_id)) return Return.valueOf(-2, "公示记录record_id不可为空");
        //添加步骤
        CDO addVoteStep = new CDO();
        addVoteStep.set("step_id", id);
        addVoteStep.set("user_id", userId);
        addVoteStep.set("property", voteInfo.getString("community_name"));
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //数据备注
        addVoteStep.set("planned_speed", "委员公示点击继续：" + sdf.format(new Date()));
        addVoteStep.set("complete_state", 1);
        //到第几大步
        addVoteStep.set("step_big", 8);
        //到第几小步
        addVoteStep.set("step_small", 1);
        this.publicAdditionsAddVoteStep(addVoteStep);
        //修改委员公示结束
        CDO updateVoteRecord = new CDO();
        updateVoteRecord.set("id", record_id);
        updateVoteRecord.set("update_time", sdf.format(new Date()));
        updateVoteRecord.set("vote_state", 1);
        voteRecordDao.updateVoteRecordById(updateVoteRecord);
        return Return.SUCCESS;
    }

    /**
     * 公示委员信息
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return publicityMembersInfo(CDO cdoRequest) {
        String id = cdoRequest.getString("id");
        if (StringUtils.isEmpty(id)) return Return.valueOf(-2, "表决id不可为空");
        String userId = cdoRequest.getString("userId");
        String seven_offline_publicity_img = cdoRequest.getString("seven_offline_publicity_img");
        if (StringUtils.isEmpty(seven_offline_publicity_img)) return Return.valueOf(-2, "请上传图片");
        CDO update = new CDO();
        update.set("id", id);
        update.set("seven_offline_publicity_img", seven_offline_publicity_img);
        voteEssentialInformationDao.updateVoteEssentialInformationById(update);
        //添加公示信息
        CDO addVote = new CDO();
        addVote.set("user_id", userId);
        addVote.set("essential_information_id", id);
        addVote.set("vote_name", "委员信息公示");
        addVote.set("vote_type", 9);//委员信息公示
        this.addVoteRecord(addVote);
        return Return.SUCCESS;
    }

    /**
     * 根据文件id查询同意状态集合
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return getFileStateListById(CDO cdoRequest) {
        String statute_id = cdoRequest.getString("statute_id");
        if (StringUtils.isEmpty(statute_id)) return Return.valueOf(-2, "文件statute_id不可为空");
        List<CDO> recordList = voteVotingRecordsDao.getVoteVotingRecordsList(cdoRequest);
        return Return.valueOf(recordList);
    }

    /**
     * 公示委员信息
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return publicityCommitteeMemberInfo(CDO cdoRequest) {
        String id = cdoRequest.getString("id");
        String userId = cdoRequest.getString("userId");
        if (StringUtils.isEmpty(id)) return Return.valueOf(-2, "表决id不可为空");
        if (StringUtils.isEmpty(userId)) return Return.valueOf(-2, "操作人userId不可为空");
        CDO voteInfo = voteEssentialInformationDao.getVoteEssentialInformationById(Integer.parseInt(id));
        if (voteInfo == null) return Return.valueOf(-2, "表决信息异常");
        //委员人数
        Integer four_members_number = voteInfo.getInteger("four_members_number");
        //候补委员人数
        Integer four_replenish_members_number = voteInfo.getInteger("four_replenish_members_number");
        four_members_number = four_members_number == null ? 0 : four_members_number;
        four_replenish_members_number = four_replenish_members_number == null ? 0 : four_replenish_members_number;
        //添加步骤信息
        CDO addVoteStep = new CDO();
        addVoteStep.set("step_id", id);
        addVoteStep.set("user_id", userId);
        addVoteStep.set("property", voteInfo.getString("community_name"));
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //数据备注
        addVoteStep.set("planned_speed", "确定公示业主大会投票结果：" + sdf.format(new Date()));
        addVoteStep.set("complete_state", 1);
        //到第几大步
        addVoteStep.set("step_big", 7);
        //到第几小步
        addVoteStep.set("step_small", 2);
        this.publicAdditionsAddVoteStep(addVoteStep);
        //修改委员候选人前几名为 准委员||准候补委员
        CDO selectUser = new CDO();
        selectUser.set("essential_information_id", id);
        selectUser.set("committee_member_status", 1);
        selectUser.set("committeeOrder", 1);//标识参数，按委员票数排序
        List<CDO> voteUserList = voteEssentialInformationDao.getVoteUserListByCDO(selectUser);
        for (int i = 0; i < voteUserList.size(); i++) {
            CDO voteUserInfo = voteUserList.get(i);
            String voteUserId = voteUserInfo.getString("id");
            CDO update = new CDO();
            update.set("id", voteUserId);
            if (i + 1 <= four_members_number + four_replenish_members_number) {
                update.set("members_state", 2);//准候补委员
            }
            if (i + 1 <= four_members_number) {
                update.set("members_state", 1);//准委员
            }
            //对象不包含此键，跳循环
            if (!update.containsKey("members_state")) continue;
            voteUserDao.updateUserInfoByCDO(update);
        }
        //修改委员投票结束
        CDO record = new CDO();
        record.set("essential_information_id", id);
        record.set("vote_type", 8);
        //委员投票活动
        CDO recordInfo = voteRecordDao.getVoteRecordByCdo(record);
        if (recordInfo != null) {
            CDO updateRecord = new CDO();
            updateRecord.set("id", recordInfo.getString("id"));
            updateRecord.set("update_time", sdf.format(new Date()));
            updateRecord.set("vote_state", 1);//1.结束 0.进行中
            voteRecordDao.updateVoteRecordById(updateRecord);
        }
        return Return.SUCCESS;
    }

    /**
     * 成立业主大会第7步 || 解聘物业第5步，延长、提前结束、公示结果 按钮点击
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return prolongOrEarlyEndOrPublicityClick(CDO cdoRequest) {
        String id = cdoRequest.getString("id");
        if (StringUtils.isEmpty(id)) return Return.valueOf(-2, "认证用户id不可为空");
        //1.延长 2.提前结束 3.公示结果
        Integer clickType = cdoRequest.getInteger("clickType");
        if (clickType == null) return Return.valueOf(-2, "操作类型clickType不可为空");
        String valStr = clickType == 1 ? "prolong_member_time_state" : clickType == 2 ? "early_end_member_state" : "whether_publicity_state";
        CDO updateVoteUser = new CDO();
        updateVoteUser.set("id", id);
        updateVoteUser.set(valStr, 1);
        voteUserDao.updateVoteUserById(updateVoteUser);
        //延长时间
        if (clickType == 1) {
            //同意人数到达标准，直接延长
            CDO voteUserInfo = voteUserDao.getVoteUserById(Integer.parseInt(id));
            if (voteUserInfo == null) return Return.valueOf(-2, "认证用户信息异常");
            String essential_information_id = voteUserInfo.getString("essential_information_id");//表决id
            CDO voteInfo = voteEssentialInformationDao.getVoteEssentialInformationById(Integer.parseInt(essential_information_id));
            if (voteInfo == null) return Return.valueOf(-2, "表决信息异常");
            //筹备组人数
            Integer preparations_number = voteInfo.getInteger("preparations_number");
            //2023-6-12，解聘物业 1.申请成立业主大会 2.解聘现物业公司
            Integer vote_type = voteInfo.getInteger("vote_type");
            Integer identity_type = voteInfo.getInteger("identity_type");
            if (vote_type == 2 && identity_type == 2) {
                preparations_number = voteInfo.getInteger("industry_committee_total");
            }
            CDO select = new CDO();
            select.set("essential_information_id", essential_information_id);
            select.set("prolong_member_time_state", 1);
            int prolongTotal = voteUserDao.getVoteUserListCount(select);//延长同意数量
            if (preparations_number != null && preparations_number != 0) {
                if (preparations_number / 2 + 1 <= prolongTotal) {
                    //可延长时间
                    Integer six_expand_time = voteInfo.getInteger("six_expand_time");
                    Date six_holding_end_time = voteInfo.getDate("six_holding_end_time");
                    Calendar calendar = Calendar.getInstance();
                    calendar.setTime(six_holding_end_time);
                    calendar.add(calendar.DATE, six_expand_time);
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                    CDO updateVote = new CDO();
                    updateVote.set("id", essential_information_id);
                    updateVote.set("six_holding_end_time", sdf.format(calendar.getTime()));
                    voteEssentialInformationDao.updateVoteEssentialInformationById(updateVote);
                }
            }
        }
        //提前结束
        if (clickType == 2) {
            //条件满足，直接结束委员候选人投票
            //同意人数到达标准，直接延长
            CDO voteUserInfo = voteUserDao.getVoteUserById(Integer.parseInt(id));
            if (voteUserInfo == null) return Return.valueOf(-2, "认证用户信息异常");
            String essential_information_id = voteUserInfo.getString("essential_information_id");//表决id
            CDO voteInfo = voteEssentialInformationDao.getVoteEssentialInformationById(Integer.parseInt(essential_information_id));
            if (voteInfo == null) return Return.valueOf(-2, "表决信息异常");
            //筹备组人数
            Integer preparations_number = voteInfo.getInteger("preparations_number");
            //2023-6-12，解聘物业 1.申请成立业主大会 2.解聘现物业公司
            Integer vote_type = voteInfo.getInteger("vote_type");
            Integer identity_type = voteInfo.getInteger("identity_type");
            if (vote_type == 2 && identity_type == 2) {
                preparations_number = voteInfo.getInteger("industry_committee_total");
            }
            CDO select = new CDO();
            select.set("essential_information_id", essential_information_id);
            select.set("early_end_member_state", 1);
            int prolongTotal = voteUserDao.getVoteUserListCount(select);//结束同意数量
            if (preparations_number != null && preparations_number != 0) {
                if (preparations_number / 2 + 1 <= prolongTotal) {
                    //修改委员候选人投票结束
                    //修改委员投票结束
                    CDO record = new CDO();
                    record.set("essential_information_id", essential_information_id);
                    record.set("vote_type", 8);
                    //修改解聘物业业主大会公示结束
                    if (vote_type == 2 && identity_type == 2) {
                        record.set("vote_type", 17);
                    }
                    //委员投票活动
                    CDO recordInfo = voteRecordDao.getVoteRecordByCdo(record);
                    if (recordInfo != null) {
                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        CDO updateRecord = new CDO();
                        updateRecord.set("id", recordInfo.getString("id"));
                        updateRecord.set("update_time", sdf.format(new Date()));
                        updateRecord.set("vote_state", 1);//1.结束 0.进行中
                        voteRecordDao.updateVoteRecordById(updateRecord);
                    }
                }
            }
        }
        return Return.SUCCESS;
    }

    /**
     * 成立业主大会第七步，延长、提前结束、公示结果 按钮统计
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return getStatisticsInfoBySeven(CDO cdoRequest) {
        String id = cdoRequest.getString("id");
        if (StringUtils.isEmpty(id)){
            return Return.valueOf(-2, "表决id不可为空");
        }
        CDO select = new CDO();
        select.set("essential_information_id", id);
        select.set("prolong_member_time_state", 1);
        int prolongTotal = voteUserDao.getVoteUserListCount(select);//延长同意数量
        select.set("prolong_member_time_state", null);
        select.set("early_end_member_state", 1);
        int earlyEndTotal = voteUserDao.getVoteUserListCount(select);//提前结束同意数量
        select.set("early_end_member_state", null);
        select.set("whether_publicity_state", 1);
        int publicityTotal = voteUserDao.getVoteUserListCount(select);//公示委员同意数量
        CDO result = new CDO();
        result.set("prolongTotal", prolongTotal);
        result.set("earlyEndTotal", earlyEndTotal);
        result.set("publicityTotal", publicityTotal);
        return Return.valueOf(result);
    }

    /**
     * 获取投票时间剩余
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return getTimeDiffBySeven(CDO cdoRequest) throws ParseException {
        String endTime = cdoRequest.getString("endTime");
        if (StringUtils.isEmpty(endTime)) {
            return Return.valueOf(-2, "endTime不可为空");
        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            sdf.parse(endTime);
        } catch (ParseException e) {
            return Return.valueOf(-2, "endTime时间格式：yyyy-MM-dd HH:mm:ss");
        }
        String startTime = cdoRequest.getString("startTime");
        if (!StringUtils.isEmpty(startTime)) {
            try {
                sdf.parse(startTime);
            } catch (ParseException e) {
                return Return.valueOf(-2, "startTime时间格式：yyyy-MM-dd HH:mm:ss");
            }
        }
        startTime = StringUtils.isEmpty(startTime) ? sdf.format(new Date()) : startTime;
        //获取俩个时间相差多少分钟
        Long time = this.getTime(startTime, endTime);
        String resultStr = null;

        if (time < 0) {
            resultStr = " 已结束";
        }
        if (time < 60 && time > 0) {
            resultStr = time.toString() + " 分钟";
        }
        //不到一天
        if (time >= 60 && time <= 1440) {
            Long hour = time / 60;
            Long minutes = time % 60;
            resultStr = hour + "小时 ";
            if (minutes > 0) {
                resultStr = hour + " 小时 " + minutes + "分钟 ";
            }
        }
        //超过一天
        if (time > 1440) {
            Long day = time / 1440;
            Long hour = time % 1440 / 60;
            Long minutes = time % 60;
            resultStr = day + "天";
            if (hour > 0) {
                resultStr = day + "天 " + hour + "小时 ";
            }
            if (minutes > 0 && hour > 0) {
                resultStr = day + "天 " + hour + "小时 " + minutes + "分钟 ";
            }
        }
        cdoRequest.set("timeCha", resultStr + "!");
        cdoRequest.set("minutes", time > 0 ? time : 0);
        return Return.valueOf(cdoRequest);
    }

    /**
     * 成立业委会，公示首次业主大会信息
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return publicityFirstOwnersMeeting(CDO cdoRequest) {
        String id = cdoRequest.getString("id");
        if (StringUtils.isEmpty(id)) return Return.valueOf(-2, "表决主键id不可为空");
        String userId = cdoRequest.getString("userId");
        String six_convene_template_img = cdoRequest.getString("six_convene_template_img");
        if (StringUtils.isEmpty(six_convene_template_img)) Return.valueOf(-2, "请上传线下公示图片");
        CDO update = new CDO();
        update.set("id", id);
        update.set("six_convene_template_img", six_convene_template_img);
        //修改表决更新线下图片信息
        voteEssentialInformationDao.updateVoteEssentialInformationById(update);
        //添加公示信息
        CDO addVote = new CDO();
        addVote.set("user_id", userId);
        addVote.set("essential_information_id", id);
        addVote.set("vote_name", "首次业主大会通知");
        addVote.set("vote_type", 7);//首次业主大会通知
        this.addVoteRecord(addVote);
        //公示状态，0.正常 1.已结束
        String publicityState = cdoRequest.getString("publicityState");
        publicityState = StringUtils.isEmpty(publicityState) ? "0" : publicityState;
        if (publicityState.equals("1")) {
            this.addSixToSeven(id);
        }
        return Return.SUCCESS;
    }

    /**
     * 第6步自动跳到第七步
     *
     * @param id
     */
    public void addSixToSeven(String id) {
        if (StringUtils.isEmpty(id)) return;
        CDO voteInfo = voteEssentialInformationDao.getVoteEssentialInformationById(Integer.parseInt(id));
        if (voteInfo == null) return;
        //只要公示过的才可进行下一步
        String six_convene_template_img = voteInfo.getString("six_convene_template_img");
        if (StringUtils.isEmpty(six_convene_template_img)) return;
        String preparation_vote_user_id = voteInfo.getString("preparation_vote_user_id");
        //表决类型：1.申请成立业主大会 2.解聘现物业公司
        Integer vote_type = voteInfo.getInteger("vote_type");
        if (vote_type == 1) {
            //添加投票公示信息
            CDO addVoteRecord = new CDO();
            addVoteRecord.set("user_id", preparation_vote_user_id);
            addVoteRecord.set("essential_information_id", id);
            addVoteRecord.set("vote_name", "候选人投票公示");
            addVoteRecord.set("vote_type", 8);//候选人投票公示
            this.addVoteRecord(addVoteRecord);
            //添加步骤信息
            CDO addVoteStep = new CDO();
            addVoteStep.set("step_id", id);
            addVoteStep.set("user_id", preparation_vote_user_id);
            addVoteStep.set("property", voteInfo.getString("community_name"));
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            //数据备注
            addVoteStep.set("planned_speed", "发起候选人投票：" + sdf.format(new Date()));
            addVoteStep.set("complete_state", 1);
            //到第几大步
            addVoteStep.set("step_big", 7);
            //到第几小步
            addVoteStep.set("step_small", 1);
            //修改，成立业主大会公示结束
            CDO record = new CDO();
            record.set("essential_information_id", id);
            record.set("vote_type", 7);
            CDO recordInfo = voteRecordDao.getVoteRecordByCdo(record);
            if (recordInfo != null) {
                CDO updateRecord = new CDO();
                SimpleDateFormat simple = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                updateRecord.set("id", recordInfo.getString("id"));
                updateRecord.set("update_time", simple.format(new Date()));
                updateRecord.set("vote_state", 1);//1.结束 0.进行中
                voteRecordDao.updateVoteRecordById(updateRecord);
            }
            this.publicAdditionsAddVoteStep(addVoteStep);
        }
        if (vote_type == 2) {
            //修改，业主大会公示结束
            CDO record = new CDO();
            record.set("essential_information_id", id);
            record.set("vote_type", 7);
            CDO recordInfo = voteRecordDao.getVoteRecordByCdo(record);
            if (recordInfo != null) {
                CDO updateRecord = new CDO();
                SimpleDateFormat simple = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                updateRecord.set("id", recordInfo.getString("id"));
                updateRecord.set("update_time", simple.format(new Date()));
                updateRecord.set("vote_state", 1);//1.结束 0.进行中
                voteRecordDao.updateVoteRecordById(updateRecord);
            }
            //添加步骤信息
            CDO addVoteStep = new CDO();
            addVoteStep.set("step_id", id);
            addVoteStep.set("user_id", preparation_vote_user_id);
            addVoteStep.set("property", voteInfo.getString("community_name"));
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            //数据备注
            addVoteStep.set("planned_speed", "业主大会公示结束");
            addVoteStep.set("complete_state", 1);
            //到第几大步
            addVoteStep.set("step_big", 5);
            //到第几小步
            addVoteStep.set("step_small", 1);
            this.publicAdditionsAddVoteStep(addVoteStep);
            //添加解聘事项至vote_statute_img
            String vote_things = voteInfo.getString("vote_things");
            List<String> thingsList = new ArrayList<>();
            if (!StringUtils.isEmpty(vote_things)) {
                CDO voteThingsCdo = voteInfo.getCDO("vote_things");
                if (voteThingsCdo != null) {
                    List<CDO> voteThingsList = voteThingsCdo.getCDOList("voteThingsList");
                    List<CDO> voteOtherThingsList = voteThingsCdo.getCDOList("voteOtherThingsList");

                    for (CDO cdo : voteThingsList) {
                        if (cdo.getBoolean("checkFlag")) {
                            thingsList.add(cdo.getString("text"));
                        }
                    }
                    for (CDO thingsCdo : voteOtherThingsList) {
                        thingsList.add(thingsCdo.getString("otherThings"));
                    }
                }
            }
            int statute_edition = 0;
            for (String thingsText : thingsList) {
                if (StringUtils.isEmpty(thingsText)) {
                    continue;
                }
                statute_edition++;
                CDO addThing = new CDO();
                addThing.set("essential_information_id", id);
                addThing.set("statute_state", 6);
                addThing.set("statute_edition", statute_edition);
                addThing.set("things_text", thingsText);
                voteStatuteImgDao.addVoteStatuteImg(addThing);
            }
            //添加解聘物业业主大会投票
            //添加投票公示信息
            CDO addVoteRecord = new CDO();
            addVoteRecord.set("essential_information_id", id);
            addVoteRecord.set("vote_name", "解聘现物业业主大会投票");
            addVoteRecord.set("vote_type", 17);//解聘现物业业主大会投票
            this.addVoteRecord(addVoteRecord);
        }
    }

    @OpenApi
    public Return testFirstOwnersMeeting(CDO cdoRequest) {
        String id = cdoRequest.getString("id");
        this.firstOwnersMeetingVoteState(id);
        return Return.valueOf("ok");
    }

    /**
     * 定时修改首次成立业委会状态
     */
    public void firstOwnersMeetingVoteState(String voteId) {
        String dayTimeStr = this.getYesterdayStr();
        CDO select = new CDO();
        select.set("six_holding_time", dayTimeStr);
        if (!StringUtils.isEmpty(voteId)) {
            select.set("six_holding_time", null);
            select.set("id", voteId);
        }
        //select.set("six_holding_time", "2023-02-03");
        //筹备组投票时间结束的信息
        List<CDO> voteList = voteEssentialInformationDao.getPreparatoryGroupListByTimer(select);
        for (CDO voteInfo : voteList) {
            String id = voteInfo.getString("id");
            this.addSixToSeven(id);
        }
    }

    /**
     * 第六步获取同意信息
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return getSixAgreeInfo(CDO cdoRequest) throws ParseException {
        String userId = cdoRequest.getString("userId");//操作人
        String id = cdoRequest.getString("id");
        if (StringUtils.isEmpty(userId)) return Return.valueOf(-2, "操作人userId不可为空");
        if (StringUtils.isEmpty(id)) return Return.valueOf(-2, "表决主键id不可为空");
        //2022-1-16，新增，3天后自动同意
        CDO voteInfo = voteEssentialInformationDao.getVoteEssentialInformationById(Integer.parseInt(id));
        if (voteInfo == null) return Return.valueOf(-2, "表决信息异常");
        String update_time = voteInfo.getString("update_time");
        if (!StringUtils.isEmpty(update_time)) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            long time = this.getTime(update_time, sdf.format(new Date()));
            if (time >= 4320) {
                //添加筹备组通过

            }
        }
        //查询该表决筹备组人员人数及同意人数，及操作人同意状态
        CDO select = new CDO();
        select.set("essential_information_id", id);
        select.set("preparation_status", 1);//是否筹备组成员：1是，0否
        //筹备组人数
        int preparationTotal = voteUserDao.getVoteUserListCount(select);
        //同意人数
        int agreeTotal = voteOwnerMeetingDao.getVoteOwnerMeetingCount(select);
        //同意状态
        select.set("user_id", userId);
        int userAgreeTotal = voteOwnerMeetingDao.getVoteOwnerMeetingCount(select);
        CDO result = new CDO();
        result.set("preparationTotal", preparationTotal);
        result.set("agreeTotal", agreeTotal);
        result.set("agreeState", userAgreeTotal > 0 ? 1 : 0);//1.已同意 0.未同意
        return Return.valueOf(result);
    }


    /**
     * 成立委员，第五步结束委员报名公示，且前往下一步
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return endMembersShowInfoAndGoToSix(CDO cdoRequest) {
        String id = cdoRequest.getString("id");
        if (StringUtils.isEmpty(id)) return Return.valueOf(-2, "公示id不可为空");
        CDO voteRecordInfo = voteRecordDao.getVoteRecordById(Integer.parseInt(id));
        if (voteRecordInfo == null) return Return.valueOf(-2, "公示信息异常，请联系客服");
        CDO voteInfo = voteEssentialInformationDao.getVoteEssentialInformationById(voteRecordInfo.getInteger("essential_information_id"));
        if (voteInfo == null) return Return.valueOf(-2, "表决信息异常，请联系客服");
        //修改公示纪录结束
        CDO updateRecord = new CDO();
        updateRecord.set("id", id);
        updateRecord.set("vote_state", 1);
        voteRecordDao.updateVoteRecordById(updateRecord);
        //添加步骤记录--步骤不变
        String userId = cdoRequest.getString("userId");
        CDO addVoteStep = new CDO();
        addVoteStep.set("step_id", voteInfo.get("id"));
        addVoteStep.set("user_id", userId);
        addVoteStep.set("property", voteInfo.getString("community_name"));
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //数据备注
        addVoteStep.set("planned_speed", "结束委员投票公示：" + sdf.format(new Date()));
        addVoteStep.set("complete_state", 1);
        //到第几大步
        addVoteStep.set("step_big", 6);
        //到第几小步
        addVoteStep.set("step_small", 1);
        this.publicAdditionsAddVoteStep(addVoteStep);
        return Return.SUCCESS;
    }


    /**
     * 公示委员报名信息
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return publicityMemberInfo(CDO cdoRequest) {
        String id = cdoRequest.getString("id");
        if (StringUtils.isEmpty(id)) return Return.valueOf(-2, "表决id不可为空");
        String userId = cdoRequest.getString("userId");
        CDO voteInfo = voteEssentialInformationDao.getVoteEssentialInformationById(Integer.parseInt(id));
        if (voteInfo == null) return Return.valueOf(-2, "表决信息异常，请联系客服");

        //添加委员候选人公示记录
        CDO addVoteRecord = new CDO();
        addVoteRecord.set("user_id", userId);
        addVoteRecord.set("essential_information_id", id);
        addVoteRecord.set("vote_name", "委员候选人公示");
        addVoteRecord.set("vote_type", 6);//委员候选人公示
        this.addVoteRecord(addVoteRecord);
        //添加步骤记录--步骤不变
        CDO addVoteStep = new CDO();
        addVoteStep.set("step_id", id);
        addVoteStep.set("user_id", userId);
        addVoteStep.set("property", voteInfo.getString("community_name"));
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //数据备注
        addVoteStep.set("planned_speed", "确定公示委员报名信息：" + sdf.format(new Date()));
        addVoteStep.set("complete_state", 1);
        //到第几大步
        addVoteStep.set("step_big", 5);
        //到第几小步
        addVoteStep.set("step_small", 2);
        this.publicAdditionsAddVoteStep(addVoteStep);
        return Return.SUCCESS;
    }

    /**
     * 手动添加委员候选人信息
     *
     * @return
     */
    @OpenApi
    public Return addMembersInfo(CDO cdoRequest) {
        String id = cdoRequest.getString("id");
        if (StringUtils.isEmpty(id)) return Return.valueOf(-2, "用户认证id不可为空");
        String user_nation = cdoRequest.getString("user_nation");
        if (StringUtils.isEmpty(user_nation)) return Return.valueOf(-2, "请填写民族");
        String user_olitical_outlook = cdoRequest.getString("user_olitical_outlook");
        String company = cdoRequest.getString("company");
        if (StringUtils.isEmpty(company)) return Return.valueOf(-2, "请填写单位");
        String user_declaration = cdoRequest.getString("user_declaration");
        if (StringUtils.isEmpty(user_declaration)) return Return.valueOf(-2, "请填写个人宣言");
        String user_coronal_photograph_img = cdoRequest.getString("user_coronal_photograph_img");
        if (StringUtils.isEmpty(user_coronal_photograph_img)) return Return.valueOf(-2, "请上传冠冕照");
        String user_consumption_proof_img = cdoRequest.getString("user_consumption_proof_img");
        if (StringUtils.isEmpty(user_consumption_proof_img)) return Return.valueOf(-2, "请上传缴费证明");
        String user_other_img = cdoRequest.getString("user_other_img");
        CDO update = new CDO();
        update.set("id", id);
        update.set("user_nation", user_nation);
        update.set("user_olitical_outlook", user_olitical_outlook);
        update.set("company", company);
        update.set("user_declaration", user_declaration);
        update.set("user_coronal_photograph_img", user_coronal_photograph_img);
        update.set("user_consumption_proof_img", user_consumption_proof_img);
        update.set("user_other_img", user_other_img);
        update.set("committee_member_status", 1);
        voteUserDao.updateVoteUserById(update);
        return Return.SUCCESS;
    }

    /**
     * 根据手机号和表决id查询该认证信息
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return getVoteUserInfoByPhoneAndVoteId(CDO cdoRequest) {
        String phone = cdoRequest.getString("phone");
        String id = cdoRequest.getString("id");
        if (StringUtils.isEmpty(phone)) return Return.valueOf(-2, "手机号phone不可为空");
        if (StringUtils.isEmpty(id)) return Return.valueOf(-2, "表决id不可为空");
        CDO voteUserInfo = voteEssentialInformationDao.getVoteUserInfoByPhoneAndVoteId(phone, id);
        if (voteUserInfo != null) {
            String user_card_code = voteUserInfo.getString("user_card_code");
            //根据身份证号获取年龄
            if (!StringUtils.isEmpty(user_card_code)) {
                Map<String, String> birAgeSex = userCardInfoUtil.getBirAgeSex(user_card_code);
                voteUserInfo.set("birthday", birAgeSex.get("birthday"));//出生日期
                voteUserInfo.set("age", birAgeSex.get("age"));//年龄
                voteUserInfo.set("sexCode", birAgeSex.get("sexCode"));//性别
            }
        }
        return Return.valueOf(voteUserInfo);
    }


    /**
     * 成立业委会第四步继续到第五步
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return fourToFiveStep(CDO cdoRequest) {
        //业主规约公示结束
        String id = cdoRequest.getString("id");
        if (StringUtils.isEmpty(id)) return Return.valueOf(-2, "表决id不可为空");
        String user_id = cdoRequest.getString("user_id");
        CDO voteInfo = voteEssentialInformationDao.getVoteEssentialInformationById(Integer.parseInt(id));
        if (voteInfo == null) return Return.valueOf(-2, "表决信息异常，请联系客服");
        //发起投票公示记录表id
        String record_id = cdoRequest.getString("record_id");
        if (StringUtils.isEmpty(record_id)) return Return.valueOf(-2, "公示记录record_id不可为空");
        CDO updateVoteRecord = new CDO();
        updateVoteRecord.set("id", record_id);
        updateVoteRecord.set("vote_state", 1);
        voteRecordDao.updateVoteRecordById(updateVoteRecord);
        //添加步骤
        CDO addVoteStep = new CDO();
        addVoteStep.set("step_id", id);
        addVoteStep.set("user_id", user_id);
        addVoteStep.set("property", voteInfo.getString("community_name"));
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //数据备注
        addVoteStep.set("planned_speed", "业主规约继续下一步时间：" + sdf.format(new Date()));
        addVoteStep.set("complete_state", 1);
        //到第几大步
        addVoteStep.set("step_big", 5);
        //到第几小步
        addVoteStep.set("step_small", 1);
        this.publicAdditionsAddVoteStep(addVoteStep);
        return Return.SUCCESS;
    }

    /**
     * 添加文件评论信息
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return addCommentInfo(CDO cdoRequest) {
        voteCommentDao.addVoteComment(cdoRequest);
        return Return.SUCCESS;
    }


    /**
     * 第四大步 公示文件或更新委员招募信息
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return publicityFileOrMembers(CDO cdoRequest) throws ParseException {
        String id = cdoRequest.getString("id");
        String userId = cdoRequest.getString("userId");
        if (StringUtils.isEmpty(id)) return Return.valueOf(-2, "文件id不可为空");
        CDO voteInfo = voteEssentialInformationDao.getVoteEssentialInformationById(Integer.parseInt(id));
        if (voteInfo == null) return Return.valueOf(-2, "表决信息异常，请联系管理员");
        //操作类型，1.文件公示 2.委员招募
        Integer updateType = cdoRequest.getInteger("updateType");
        //2023-1-10，后端判断当前时间往后推7天时间段为业主端公示时间段
        if (updateType == 2) {
            SimpleDateFormat ymdSdf = new SimpleDateFormat("yyyy-MM-dd");
            String nowTime = ymdSdf.format(new Date());
            Calendar cal = Calendar.getInstance();
            cal.setTime(ymdSdf.parse(nowTime));
            cal.add(Calendar.DATE, +6);
            Date endTime = cal.getTime();
            cdoRequest.set("four_publicity_time", nowTime);
            cdoRequest.set("four_publicity_end_time", ymdSdf.format(endTime));
        }
        voteEssentialInformationDao.updateVoteEssentialInformationById(cdoRequest);
        //添加步骤
        CDO addVoteStep = new CDO();
        addVoteStep.set("step_id", id);
        addVoteStep.set("user_id", userId);
        addVoteStep.set("property", voteInfo.getString("community_name"));
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //数据备注
        addVoteStep.set("planned_speed", updateType == 1 ? "上传文件公示信息时间：" : "填写上传招募委员时间：" + sdf.format(new Date()));
        addVoteStep.set("complete_state", 1);
        //到第几大步
        addVoteStep.set("step_big", 4);
        //到第几小步
        //提交委员表单返回至第一步
        addVoteStep.set("step_small", updateType == 1 ? 3 : 1);
        this.publicAdditionsAddVoteStep(addVoteStep);
        if (updateType == 2) {
            //添加业主规约公示记录
            CDO addVoteRecord = new CDO();
            addVoteRecord.set("user_id", userId);
            addVoteRecord.set("essential_information_id", id);
            addVoteRecord.set("vote_name", "业主规约公示");
            addVoteRecord.set("vote_type", 4);
            this.addVoteRecord(addVoteRecord);
        }
        return Return.SUCCESS;
    }

    /**
     * 业主端获取文件评论记录，无分页
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return getOwnerFileCommentList(CDO cdoRequest) {
        //文件主键id
        String statute_id = cdoRequest.getString("statute_id");
        if (StringUtils.isEmpty(statute_id)) return Return.valueOf(-2, "文件id不可为空");
        List<CDO> commentsList = voteCommentDao.getVoteCommentList(cdoRequest);
        for (CDO commentInfo : commentsList) {
            Date begin_time = commentInfo.getDate("begin_time");
            if (begin_time != null) {
                commentInfo.set("timeStr", timeUtil.getStrByDate(begin_time));
            }
        }
        return Return.valueOf(commentsList);
    }

    /**
     * 获取文件评论集合
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return getFileCommentsList(CDO cdoRequest) {
        //文件主键id
        String statute_id = cdoRequest.getString("statute_id");
        if (StringUtils.isEmpty(statute_id)) return Return.valueOf(-2, "文件statute_id不可为空");
        Integer pageIndex = cdoRequest.getInteger("pageIndex") - 1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> commentsList = voteCommentDao.getVoteCommentList(cdoRequest);
        boolean isEndPage = false;
        if (commentsList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", commentsList);
        int total = voteCommentDao.getVoteCommentListCount(cdoRequest);
        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }

    /**
     * 获取文件同意拒绝详情集合
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return getFileDetailConsentOrRefusalList(CDO cdoRequest) {
        //文件主键id
        String id = cdoRequest.getString("id");
        if (StringUtils.isEmpty(id)) return Return.valueOf(-2, "文件id不可为空");
        List<CDO> detailList = voteStatuteImgDao.getDetailListById(id);
        return Return.valueOf(detailList);
    }

    /**
     * 同意或拒绝文件
     *
     * @return
     */
    @OpenApi
    @RepeatSubmit(limitType = RepeatSubmit.Type.TOKEN, returnType = RepeatSubmit.ReturnType.RETURN)
    public Return agreeOrRefuseFile(CDO cdoRequest) {
        //文件主键id
        String id = cdoRequest.getString("id");
        if (StringUtils.isEmpty(id)) return Return.valueOf(-2, "文件id不可为空");
        CDO fileInfo = voteStatuteImgDao.getVoteStatuteImgById(Integer.parseInt(id));
        if (fileInfo == null) return Return.valueOf(-2, "文件信息异常，请联系管理员");
        String user_id = cdoRequest.getString("user_id");
        if (StringUtils.isEmpty(user_id)) return Return.valueOf(-2, "操作人id不可为空");
        //1.同意 2.拒绝
        Integer state = cdoRequest.getInteger("state");
        if (state == null) return Return.valueOf(-2, "同意状态不可为空");
        //根据user_id 和 表决id 查询当前操作人的信息
        CDO selectVoteUser = new CDO();
        selectVoteUser.set("user_id", user_id);
        selectVoteUser.set("essential_information_id", fileInfo.getString("essential_information_id"));
        CDO voteUserInfo = voteUserDao.getVoteUser(selectVoteUser);
        if (voteUserInfo == null) return Return.valueOf(-2, "用户信息异常");
        //添加同意拒绝记录
        CDO addRecord = new CDO();
        addRecord.set("statute_id", id);
        addRecord.set("user_id", user_id);
        addRecord.set("user_name", voteUserInfo.getString("full_name"));
        addRecord.set("user_building_number", voteUserInfo.getString("building_number"));
        addRecord.set("record_state", state);
        addRecord.set("record_type", cdoRequest.getString("record_type"));
        addRecord.set("record_reason", cdoRequest.getString("record_reason"));
        CDO voteVotingRecords = voteVotingRecordsDao.getVoteVotingRecords(addRecord);
        if(Objects.nonNull(voteVotingRecords)){
            return Return.valueOf(-2,"请勿重复提交",false);
        }
            voteVotingRecordsDao.addVoteVotingRecords(addRecord);
            //修改同意拒绝人数信息
            CDO update = new CDO();
            String stateStr = state == 1 ? "agree" : "refuse";
            update.set(stateStr, "1");
            update.set("id", id);
            voteStatuteImgDao.updateResultById(update);
        return Return.SUCCESS;
    }

    /**
     * 业主端获取业主规约文件集合
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return getOwnerAppFileListById(CDO cdoRequest) {
        String essential_information_id = cdoRequest.getString("essential_information_id");
        if (StringUtils.isEmpty(essential_information_id)) return Return.valueOf(-2, "表决id不可为空");
        //业主端候选人投票查询文件标识参数
        String userId = cdoRequest.getString("userId");
        String ownerSelect = cdoRequest.getString("ownerSelect");
        String ownerAppSelect = cdoRequest.getString("ownerAppSelect");//业主端以业主身份同意标识参数
        String fileSelect = cdoRequest.getString("fileSelect");//文件查询标识
        List<CDO> voteFileList = voteEssentialInformationDao.getOwnerAppVoteFileList(cdoRequest);
        CDO selectRecord;
        for (CDO fileInfo : voteFileList) {
            if (!StringUtils.isEmpty(fileInfo.getString("statute_img"))){
                String statute_img = fileInfo.getString("statute_img");
                fileInfo.set("statute_img",statute_img);
            }
            String id = fileInfo.getString("id");
            //查询当前操作人是否同意过
            if (!StringUtils.isEmpty(userId) && !StringUtils.isEmpty(ownerSelect)) {
                CDO select = new CDO();
                select.set("statute_id", id);
                select.set("user_id", userId);
                select.set("record_state", 1);
                if (!StringUtils.isEmpty(ownerAppSelect)) select.set("record_type", 1);//1.业主身份同意
                int recordTotal = voteVotingRecordsDao.getVoteVotingRecordsCount(select);
                fileInfo.set("agreeClickFlag", recordTotal > 0 ? true : false);
            }
            String statute_state = fileInfo.getString("statute_state");
            fileInfo.set("openFlag", false);//抽屉默认合住
            //查询历史版本文件
            selectRecord = new CDO();
            selectRecord.set("essential_information_id", essential_information_id);
            selectRecord.set("statute_state", statute_state);
            selectRecord.set("id", id);
            List<CDO> voteFileList1 = voteEssentialInformationDao.getVoteFileList(selectRecord);
            for (CDO cdo : voteFileList1) {
                if (!StringUtils.isEmpty(cdo.getString("statute_img"))){
                    String statute_img = cdo.getString("statute_img");
                    cdo.set("statute_img",statute_img);
                }
            }
            fileInfo.set("recordList",voteFileList1 );

        }
        return Return.valueOf(voteFileList);
    }

    /**
     * 业主规约查询文件信息
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return getVoteFileInfo(CDO cdoRequest) {
        //筹备组人员id
        String userId = cdoRequest.getString("userId");
        List<CDO> voteFileList = voteEssentialInformationDao.getVoteFileList(cdoRequest);
        //返回的集合，老版本
        List<CDO> oldFileList = null;
        //最新版本
        CDO newFileInfo = null;
        if (voteFileList != null && voteFileList.size() > 0) {
            newFileInfo = voteFileList.get(voteFileList.size() - 1);
            voteFileList.remove(voteFileList.size() - 1);
            oldFileList = voteFileList;
        }
        if (newFileInfo != null) {
            //查询当前操作人是否同意拒绝过
            if (!StringUtils.isEmpty(userId)) {
                CDO selectRecord = new CDO();
                selectRecord.set("user_id", userId);
                selectRecord.set("statute_id", newFileInfo.getString("id"));
                int total = voteVotingRecordsDao.getVoteVotingRecordsCount(selectRecord);
                Boolean opinionFlag = total > 0 ? true : false;
                newFileInfo.set("opinionFlag", opinionFlag);
            }

        }
        CDO result = new CDO();
        result.set("newFileInfo", newFileInfo);
        result.set("oldFileList", oldFileList);
        return Return.valueOf(result);
    }

    /**
     * 公示筹备组信息
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return publicityPreparatoryInfo(CDO cdoRequest) {
        //表决id
        String id = cdoRequest.getString("id");
        String user_id = cdoRequest.getString("user_id");
        if (StringUtils.isEmpty(id)) return Return.valueOf(-2, "表决id不可为空");
        CDO voteInfo = voteEssentialInformationDao.getVoteEssentialInformationById(Integer.parseInt(id));
        if (voteInfo == null) {
            return Return.valueOf(-2, "表决信息异常");
        }
        //表决类型：1.申请成立业主大会 2.解聘现物业公司
        Integer vote_type = voteInfo.getInteger("vote_type");
        //添加筹备组成员公示记录
        CDO addVoteRecord = new CDO();
        addVoteRecord.set("user_id", user_id);
        addVoteRecord.set("essential_information_id", id);
        addVoteRecord.set("vote_name", vote_type == 1 ? "筹备组成员公示" : "工作组成员公示");
        addVoteRecord.set("vote_type", 3);
        this.addVoteRecord(addVoteRecord);
        //修改筹备组报名结束
        CDO record = new CDO();
        record.set("essential_information_id", id);
        record.set("vote_type", 1);
        CDO recordInfo = voteRecordDao.getVoteRecordByCdo(record);
        if (recordInfo != null) {
            CDO updateRecord = new CDO();
            SimpleDateFormat simple = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            updateRecord.set("id", recordInfo.getString("id"));
            updateRecord.set("update_time", simple.format(new Date()));
            updateRecord.set("vote_state", 1);//1.结束 0.进行中
            voteRecordDao.updateVoteRecordById(updateRecord);
        }
        return Return.SUCCESS;
    }

    @OpenApi
    public Return testUpdateMembersVoteStateByTimer(CDO cdo) {
        String id = cdo.getString("id");
        this.updateMembersVoteStateByTimer(id);
        return Return.SUCCESS;
    }


    /**
     * 定时修改委员报名公示状态
     */
    public void updateMembersVoteStateByTimer(String voteId) {
        String dayTimeStr = this.getYesterdayStr();
        SimpleDateFormat simple = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        CDO select = new CDO();
        //委员报名结束时间
        select.set("five_registration_end_time", dayTimeStr);
        if (!StringUtils.isEmpty(voteId)) {
            select.set("five_registration_end_time", null);
            select.set("id", voteId);
        }
        List<CDO> membersList = voteEssentialInformationDao.getPreparatoryGroupListByTimer(select);
        for (CDO voteInfo : membersList) {
            String id = voteInfo.getString("id");
            CDO record = new CDO();
            record.set("essential_information_id", id);
            record.set("vote_type", 5);//招募委员公示
            //筹备组投票活动
            CDO recordInfo = voteRecordDao.getVoteRecordByCdo(record);
            if (recordInfo == null) continue;
            CDO updateRecord = new CDO();
            updateRecord.set("id", recordInfo.getString("id"));
            updateRecord.set("update_time", simple.format(new Date()));
            updateRecord.set("vote_state", 1);//1.结束 0.进行中
            //修改该筹备组投票结束
            voteRecordDao.updateVoteRecordById(updateRecord);
        }
    }


    /**
     * 测试修改筹备组状态
     *
     * @param cdo
     * @return
     * @throws ParseException
     */
    @OpenApi
    public Return testPreparatoryGroupVoteStateByTimer(CDO cdo) throws ParseException {
        String id = cdo.getString("id");
        this.updatePreparatoryGroupVoteStateByTimer(id);
        return Return.SUCCESS;
    }


    /**
     * 定时修改筹备组 || 谈判小组投票状态
     */
    public void updatePreparatoryGroupVoteStateByTimer(String voteId) {
        String dayTimeStr = this.getYesterdayStr();
        SimpleDateFormat simple = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        CDO select = new CDO();
        select.set("preparations_vote_end_time", dayTimeStr);
        if (!StringUtils.isEmpty(voteId)) {
            select.set("preparations_vote_end_time", null);
            select.set("id", voteId);
        }
        //筹备组投票时间结束的信息
        List<CDO> preparatoryGroupList = voteEssentialInformationDao.getPreparatoryGroupListByTimer(select);
        for (CDO voteInfo : preparatoryGroupList) {
            String id = voteInfo.getString("id");
            //谈判小组标识
            String negotiation_vote_end_time = voteInfo.getString("negotiation_vote_end_time");

            //筹备组报名人数
            Integer applicationCount = voteInfo.getInteger("applicationCount");
            //已有筹备组人员人数（业主人员+非业主人员）
            Integer preparationsCount = voteInfo.getInteger("preparationsCount");
            //手动添加的筹备组人员(非业主人员)
            Integer manualAddCount = voteInfo.getInteger("manualAddCount");
            //需要的筹备组人数
            Integer preparations_number = voteInfo.getInteger("preparations_number");
            if (preparations_number == null) continue;
            //剩余所需的筹备组人数
            Integer ownerShouldTotal = preparations_number - manualAddCount;
            CDO record = new CDO();
            record.set("essential_information_id", id);
            record.set("vote_type", 2);
            String vote_things = voteInfo.getString("vote_things");
            if (!StringUtils.isEmpty(vote_things)) {
                record.set("vote_type", 15);//委托人投票
            }
            if (!StringUtils.isEmpty(negotiation_vote_end_time)) {
                record.set("vote_type", 20);//选聘物业竞争性小组业主投票
            }
            //筹备组投票活动
            CDO recordInfo = voteRecordDao.getVoteRecordByCdo(record);
            if (recordInfo == null) continue;
            CDO updateRecord = new CDO();
            updateRecord.set("id", recordInfo.getString("id"));
            updateRecord.set("update_time", simple.format(new Date()));
            updateRecord.set("vote_state", 1);//1.结束 0.进行中
            //修改该筹备组投票结束
            voteRecordDao.updateVoteRecordById(updateRecord);
            if (ownerShouldTotal > 0) {
                //取前ownerShouldTotal报名人为筹备组
                CDO selectUser = new CDO();
                selectUser.set("essential_information_id", id);
                selectUser.set("ownerShouldTotal", ownerShouldTotal);
                if (!StringUtils.isEmpty(vote_things)) {
                    selectUser.set("ownerShouldTotal", preparations_number);
                }
                if (!StringUtils.isEmpty(negotiation_vote_end_time)) {
                    selectUser.set("ownerShouldTotal", voteInfo.getInteger("negotiation_owner_total"));
                }
                List<CDO> userList = new ArrayList<>();
                if (!StringUtils.isEmpty(vote_things)) {
                    userList = voteEssentialInformationDao.getClientUserListByOrder(selectUser);
                } else if (!StringUtils.isEmpty(negotiation_vote_end_time)) {
                    userList = voteEssentialInformationDao.getNegotiationListByOrder(selectUser);
                } else {
                    userList = voteEssentialInformationDao.getPreparationUserListByOrder(selectUser);
                }
                CDO updateUser;
                if (userList != null) {
                    for (CDO voteUserInfo : userList) {
                        updateUser = new CDO();
                        updateUser.set("id", voteUserInfo.getString("id"));
                        if (!StringUtils.isEmpty(vote_things)) {
                            updateUser.set("members_state", 1);
                        } else if (!StringUtils.isEmpty(negotiation_vote_end_time)) {
                            updateUser.set("whether_negotiation_team", 1);
                        } else {
                            updateUser.set("preparation_status", 1);
                        }
                        voteUserDao.updateVoteUserById(updateUser);
                    }
                }
            }
        }
    }

    /**
     * 测试修改筹备组状态
     *
     * @param cdo
     * @return
     * @throws ParseException
     */
    @OpenApi
    public Return testPreparatoryGroupState(CDO cdo) throws ParseException {
        //修改哪个表决
        String id = cdo.getString("id");
        this.updatePreparatoryGroupApplicationStateByTimer(id);
        return Return.SUCCESS;
    }


    /**
     * 定时修改筹备组报名状态
     */
    public void updatePreparatoryGroupApplicationStateByTimer(String voteId) throws ParseException {
        String dayTimeStr = this.getYesterdayStr();
        SimpleDateFormat simple = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        CDO select = new CDO();
        select.set("applicationEndTime", dayTimeStr);
        if (!StringUtils.isEmpty(voteId)) {
            select.set("applicationEndTime", null);
            select.set("id", voteId);
        }
        //select.set("applicationEndTime","2023-01-20");
        //筹备组报名时间结束的信息
        //2023-6-5，筹备组查询新增vote_things检索，过滤解聘物业第三步的委托人招募信息
        //2023-6-29，新增谈判小组查询
        List<CDO> preparatoryGroupList = voteEssentialInformationDao.getPreparatoryGroupListByTimer(select);
        for (CDO voteInfo : preparatoryGroupList) {
            String id = voteInfo.getString("id");
            if (!StringUtils.isEmpty(voteInfo.getString("negotiation_enroll_end_time"))) {
                //修改谈判组报名状态；新增谈判组谈判公示
                //所需谈判小组业主人数
                Integer negotiation_owner_total = voteInfo.getInteger("negotiation_owner_total");
                if (negotiation_owner_total == null) continue;
                CDO selectNegotiationTotal = new CDO();
                selectNegotiationTotal.set("essential_information_id", id);
                selectNegotiationTotal.set("whether_owner", 1);
                selectNegotiationTotal.set("whether_negotiation_team", 0);
                int negotiationTotal = voteUserDao.getVoteUserListCount(selectNegotiationTotal);
                CDO record = new CDO();
                record.set("essential_information_id", id);
                record.set("vote_type", 19);
                CDO recordInfo = voteRecordDao.getVoteRecordByCdo(record);
                if (recordInfo == null) continue;
                //修改谈判组报名结束状态
                CDO updateVoteRecord = new CDO();
                updateVoteRecord.set("id", recordInfo.getString("id"));
                updateVoteRecord.set("update_time", simple.format(new Date()));
                updateVoteRecord.set("vote_state", 1);
                if (negotiationTotal <= negotiation_owner_total) {
                    //仍可继续报名，直至人满后结束
                    updateVoteRecord.set("vote_state", 0);
                    //修改已报名人为谈判组
                    CDO updateNegotiation = new CDO();
                    updateNegotiation.set("essential_information_id", id);
                    voteEssentialInformationDao.updateNegotiationInfoByCDO(updateNegotiation);
                }
                voteRecordDao.updateVoteRecordById(updateVoteRecord);
                //添加谈判组投票
                CDO addVoteRecord = new CDO();
                addVoteRecord.set("vote_type", 20);
                addVoteRecord.set("user_id", voteInfo.getString("preparation_vote_user_id"));
                addVoteRecord.set("essential_information_id", id);
                addVoteRecord.set("vote_name", "选聘物业竞争性小组业主投票");
                this.addVoteRecord(addVoteRecord);
                continue;
            }

            //报名人数
            Integer applicationCount = voteInfo.getInteger("applicationCount");
            //已有筹备组人员人数（业主人员+非业主人员）
            Integer preparationsCount = voteInfo.getInteger("preparationsCount");
            //手动添加的筹备组人员(非业主人员)
            Integer manualAddCount = voteInfo.getInteger("manualAddCount");
            //需要的筹备组人数
            Integer preparations_number = voteInfo.getInteger("preparations_number");
            if (preparations_number == null) continue;
            //如果报名人员大于应招募的业主筹备组人员，进行投票选择筹备组
            //报名人数不够，已报名的人直接为筹备组成员，报名继续，之后报名直接为筹备组，无需投票，直到人数达到，报名结束
            Integer ownerShouldTotal = preparations_number - manualAddCount;
            //报名人数小于应报名人数 并且 已有筹备组人数不足
            //1.成立业主委员会  2.解聘物业公司 3.选聘物业公司
            Integer vote_type = voteInfo.getInteger("vote_type");
            CDO record = new CDO();
            record.set("essential_information_id", id);
            record.set("vote_type", 1);
            //解聘物业，委托人招募标识参数
            String vote_things = voteInfo.getString("vote_things");
            //2023-6-20，新增选聘物业委员投票，根据步骤判断是工作组还是委托人
//            if(vote_type == 3){
//                CDO stepInfo = this.getStepInfoById(id);
//                if (stepInfo != null) {
//                    Integer bigStep = stepInfo.getInteger("voteType");
//                    if(bigStep == 3){
//                        vote_things = "1";
//                    }
//                }
//            }
            if (!StringUtils.isEmpty(vote_things)) {
                record.set("vote_type", 14);
            }
            //1.筹备组招募公示  14.委托人招募公示
            CDO recordInfo = voteRecordDao.getVoteRecordByCdo(record);
            if (recordInfo == null) continue;
            CDO updateRecord = new CDO();
            updateRecord.set("id", recordInfo.getString("id"));
            updateRecord.set("update_time", simple.format(new Date()));
            updateRecord.set("vote_state", 1);//1.结束 0.进行中
            CDO addVoteRecord = new CDO();
            if (!StringUtils.isEmpty(vote_things)) {
                //查询委员报名人数
                CDO selectMemberTotal = new CDO();
                selectMemberTotal.set("essential_information_id", id);
                selectMemberTotal.set("committee_member_status", 1);
                int memberTotal = voteUserDao.getVoteUserListCount(selectMemberTotal);
                if (memberTotal <= preparations_number) {
                    //可继续报名
                    updateRecord.set("vote_state", 0);
                    //修改报名人为委员
                    CDO updateMember = new CDO();
                    updateMember.set("essential_information_id", id);
                    voteEssentialInformationDao.updateMemberInfoByCDO(updateMember);
                }
            } else {
                //人数不够进行报名
                if (vote_type == 1) {
                    if (applicationCount < ownerShouldTotal && preparationsCount < preparations_number) {
                        updateRecord.set("vote_state", 0);
                        //修改已报名的人为筹备组
                        CDO updatePreparations = new CDO();
                        updatePreparations.set("essential_information_id", id);
                        voteEssentialInformationDao.updatePreparationsByCDO(updatePreparations);
                    }
                }
                //解聘物业
                if (vote_type == 2) {
                    if (applicationCount <= preparations_number) {
                        updateRecord.set("vote_state", 0);
                        //修改已报名的人为筹备组
                        CDO updatePreparations = new CDO();
                        updatePreparations.set("essential_information_id", id);
                        voteEssentialInformationDao.updatePreparationsByCDO(updatePreparations);
                        if (applicationCount == preparations_number) {
                            //报名人员 = 应招募人员，投票结束
                            addVoteRecord.set("vote_state", 1);
                            updateRecord.set("vote_state", 0);
                        }
                    }
                }
            }
            voteRecordDao.updateVoteRecordById(updateRecord);
            //添加筹备组投票步骤
            //添加公示记录
            addVoteRecord.set("user_id", voteInfo.getString("preparation_vote_user_id"));
            addVoteRecord.set("essential_information_id", id);
            addVoteRecord.set("vote_name", vote_type == 1 ? "筹备组招募人员投票" : "工作组招募人员投票");
            addVoteRecord.set("vote_type", 2);
            if (!StringUtils.isEmpty(vote_things)) {
                addVoteRecord.set("vote_name", "委托人招募人员投票");
                addVoteRecord.set("vote_type", 15);
            }
            this.addVoteRecord(addVoteRecord);
        }
    }

    /**
     * 获取昨天
     *
     * @return
     */
    public String getYesterdayStr() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = Calendar.getInstance();
        try {
            calendar.setTime(sdf.parse(sdf.format(new Date())));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        calendar.add(Calendar.DATE, -1);
        return sdf.format(calendar.getTime());
    }

    /**
     * 业主端校验是否投过票
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return getVoteCountByIdAndVoteType(CDO cdoRequest) {
        String essential_information_id = cdoRequest.getString("essential_information_id");
        String voteType = cdoRequest.getString("voteType");
        String user_id = cdoRequest.getString("user_id");
        //判断是否投过票
        CDO verifyVote = new CDO();
        verifyVote.set("essential_information_id", essential_information_id);
        verifyVote.set("vote_user", user_id);
        verifyVote.set("vote_user_id", cdoRequest.getString("vote_user_id"));
        verifyVote.set("recommend_state", voteType);
        verifyVote.set("state", 0);
        int voteTotal = voteEssentialInformationDao.getVoteUserRecordListByCDOTotal(verifyVote);
        return Return.valueOf(voteTotal);
    }

    /**
     * 业主端查询表决被投票人员集合,无分页
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return getOwnerAppVoteUserList(CDO cdoRequest) {
        //1.筹备组投票
        Integer voteType = cdoRequest.getInteger("voteType");
        voteType = voteType != null ? voteType : 0;
        //登录人id
        String user_id = cdoRequest.getString("user_id");
        //表决主键id
        String essential_information_id = cdoRequest.getString("essential_information_id");
        //筹备组候选人
        if (voteType == 1) {
            cdoRequest.set("preparation_status", 0);
            cdoRequest.set("preparation_enroll", 1);
        }
        //委员候选人 || 解聘物业委托人查询
        if (voteType == 2 || voteType == 7) {
            cdoRequest.set("committee_member_status", 1);
        }
        //4.主任投票 5.副主任
        if (voteType == 4 || voteType == 5) {
            cdoRequest.set("committee_member_status", 1);
        }
        //6.工作组查询
        if (voteType == 6) {
            cdoRequest.set("preparation_status", 1);
        }
        //9.谈判小组业主查询
        if (voteType == 9) {
            cdoRequest.set("whether_negotiation_team", 0);
            cdoRequest.set("whether_owner", 1);
        }
        //空头像
        String nullAppImg = "https://clhy-img.oss-cn-beijing.aliyuncs.com/logo/avatar.jpg";

        List<CDO> voteUserList = voteEssentialInformationDao.getVoteUserListByCDO(cdoRequest);
        CDO verifyVote;
        for (CDO voteUserInfo : voteUserList) {
            String id = voteUserInfo.getString("id");
            String user_card_code = voteUserInfo.getString("user_card_code");
            //根据身份证号获取年龄
            if (!StringUtils.isEmpty(user_card_code)) {
                Map<String, String> birAgeSex = userCardInfoUtil.getBirAgeSex(user_card_code);
                voteUserInfo.set("birthday", birAgeSex.get("birthday"));//出生日期
                voteUserInfo.set("age", birAgeSex.get("age"));//年龄
                voteUserInfo.set("sexCode", birAgeSex.get("sexCode"));//性别
            }
            //无冠冕照，展示助业网头像
            String user_coronal_photograph_img = voteUserInfo.getString("user_coronal_photograph_img");
            String appHeadImg = voteUserInfo.getString("appHeadImg");
            if (StringUtils.isEmpty(user_coronal_photograph_img)) {
                voteUserInfo.set("user_coronal_photograph_img", !StringUtils.isEmpty(appHeadImg) ? appHeadImg : nullAppImg);
            }
            //判断是否投过票
            verifyVote = new CDO();
            verifyVote.set("vote_user", user_id);
            verifyVote.set("vote_user_id", id);
            verifyVote.set("recommend_state", voteType);
            verifyVote.set("state", 0);
            int voteTotal = voteEssentialInformationDao.getVoteUserRecordListByCDOTotal(verifyVote);
            voteUserInfo.set("whetherVote", false);
            if (voteTotal > 0) {
                voteUserInfo.set("whetherVote", true);
            }
//            //该人票数
//            CDO selectVoteTotal = new CDO();
//            selectVoteTotal.set("vote_user_id",id);
//            selectVoteTotal.set("recommend_state",voteType);
//            voteUserInfo.set("voteTotal", voteEssentialInformationDao.getVoteUserRecordListByCDOTotal(selectVoteTotal));
        }
        return Return.valueOf(voteUserList);
    }

    /**
     * 业主端报名
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return ownerAppApplication(CDO cdoRequest) {
        //认证用户id
        String voteUserId = cdoRequest.getString("voteUserId");
        if (StringUtils.isEmpty(voteUserId)) return Return.valueOf(-2, "认证用户voteUserId不可为空");
        CDO voteUserInfo = voteUserDao.getVoteUserById(Integer.parseInt(voteUserId));
        if (voteUserInfo == null) return Return.valueOf(-2, "认证用户信息异常");
        //报名类型 1.筹备组报名  5.委员报名
        Integer applicationType = cdoRequest.getInteger("applicationType");
        if (applicationType == null) return Return.valueOf(-2, "报名类型不可为空");
        CDO updateVoteUser = new CDO();
        updateVoteUser.set("id", voteUserId);
        updateVoteUser.set("user_nation", cdoRequest.getString("user_nation"));//民族
        updateVoteUser.set("user_olitical_outlook", cdoRequest.getString("user_olitical_outlook"));//政治面貌
        updateVoteUser.set("user_declaration", cdoRequest.getString("user_declaration"));//个人宣言
        updateVoteUser.set("user_coronal_photograph_img", cdoRequest.getString("user_coronal_photograph_img"));//冠冕照
        updateVoteUser.set("user_consumption_proof_img", cdoRequest.getString("user_consumption_proof_img"));//缴费证明
        updateVoteUser.set("user_other_img", cdoRequest.getString("user_other_img"));//其它材料
        updateVoteUser.set("company", cdoRequest.getString("company"));//单位
        //筹备组报名
        if (applicationType == 1) {
            updateVoteUser = this.preparatoryGroupApplication(updateVoteUser);
        }
        //委员报名
        if (applicationType == 5) {
            Integer committee_member_status = voteUserInfo.getInteger("committee_member_status");
            //0.未报名 3.资格被取消 4.资格被取消重新报名
            committee_member_status = committee_member_status == null ? 0 : committee_member_status;
            updateVoteUser.set("committee_member_status", committee_member_status == 0 ? 1 : 4);
        }
        //2023-6-5，新增解聘物业委托人报名 即为委员报名
        if (applicationType == 14) {
            Integer committee_member_status = voteUserInfo.getInteger("committee_member_status");
            //0.未报名 3.资格被取消 4.资格被取消重新报名
            committee_member_status = committee_member_status == null ? 0 : committee_member_status;
            updateVoteUser.set("committee_member_status", committee_member_status == 0 ? 1 : 4);
        }
        //谈判组业主报名
        if (applicationType == 19) {
            //已为谈判小组成员，不可报名
            if ("1".equals(voteUserInfo.getString("whether_negotiation_team"))) {
                return Return.valueOf(-2, "您已为谈判小组成员，无须报名");
            }
            updateVoteUser.set("whether_owner", 1);
            //报名时间结束且人员未满，报名直接为谈判组人员
            CDO selectNegotiationTotal = new CDO();
            selectNegotiationTotal.set("essential_information_id", voteUserInfo.getString("essential_information_id"));
            selectNegotiationTotal.set("whether_owner", 1);
            selectNegotiationTotal.set("whether_negotiation_team", 0);
            int negotiationTotal = voteUserDao.getVoteUserListCount(selectNegotiationTotal);
            CDO voteInfo = voteEssentialInformationDao.getVoteEssentialInformationById(voteUserInfo.getInteger("essential_information_id"));
            //报名结束时间
            Date negotiation_enroll_end_time = voteInfo.getDate("negotiation_enroll_end_time");
            //所需业主谈判组人数
            Integer negotiation_owner_total = voteInfo.getInteger("negotiation_owner_total");
            if (negotiation_enroll_end_time.getTime() < new Date().getTime()) {
                //报名时间结束
                updateVoteUser.set("whether_negotiation_team", 1);
                if (negotiationTotal + 1 == negotiation_owner_total) {
                    //修改谈判小组报名公示结束
                    CDO record = new CDO();
                    record.set("essential_information_id", voteUserInfo.getString("essential_information_id"));
                    record.set("vote_type", 19);
                    CDO recordInfo = voteRecordDao.getVoteRecordByCdo(record);
                    if (recordInfo != null) {
                        //修改谈判组报名结束状态
                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        CDO updateVoteRecord = new CDO();
                        updateVoteRecord.set("id", recordInfo.getString("id"));
                        updateVoteRecord.set("update_time", sdf.format(new Date()));
                        updateVoteRecord.set("vote_state", 1);
                        voteRecordDao.updateVoteRecordById(updateVoteRecord);
                    }
                }
            }

        }
        String errorMsg = updateVoteUser.getString("errorMsg");
        if (!StringUtils.isEmpty(errorMsg)) return Return.valueOf(-2, errorMsg);
        voteUserDao.updateVoteUserById(updateVoteUser);
        return Return.SUCCESS;
    }

    /**
     * 根据用户认证主键id获取信息
     *
     * @return
     */
    @OpenApi
    public Return getVoteUserInfoById(CDO cdoRequest) {
        //认证用户id
        String id = cdoRequest.getString("id");
        if (StringUtils.isEmpty(id)) return Return.valueOf(-2, "认证用户id不可为空");
        CDO voteUserInfo = voteUserDao.getVoteUserById(Integer.parseInt(id));
        return Return.valueOf(voteUserInfo);
    }

    /**
     * 筹备组报名业务处理
     *
     * @param cdo
     */
    public CDO preparatoryGroupApplication(CDO cdo) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date nowDate = new Date();
        String nowDateStr = sdf.format(nowDate);
        cdo.set("preparation_enroll", 1);//筹备组已报名
        cdo.set("preparation_time", nowDateStr);//报名时间

        //认证用户信息
        CDO voteUserInfo = voteUserDao.getVoteUserById(cdo.getInteger("id"));
        if (voteUserInfo == null) {
            cdo.set("errorMsg", "认证用户信息异常，请稍后再试");
            return cdo;
        }
        //表决信息
        CDO voteInfo = voteEssentialInformationDao.getVoteEssentialInformationById(voteUserInfo.getInteger("essential_information_id"));
        if (voteInfo == null) {
            cdo.set("errorMsg", "表决信息异常，请联系客服");
            return cdo;
        }
        //报名时间
        String start_time = voteInfo.getString("preparations_start_time");
        String end_time = voteInfo.getString("preparations_end_time");
        if (StringUtils.isEmpty(start_time) || StringUtils.isEmpty(end_time)) {
            cdo.set("errorMsg", "报名时间异常，请联系客服");
            return cdo;
        }
        start_time = start_time + " 00:00:00";
        end_time = end_time + " 23:59:59";
        Date startDate = null;
        Date endDate = null;
        try {
            startDate = sdf.parse(start_time);
            endDate = sdf.parse(end_time);
        } catch (ParseException e) {
            cdo.set("errorMsg", "报名时间异常，请联系客服");
            return cdo;
        }
        //报名时间在设置的报名时间之内，不可直接为筹备组成员，在设置时间之后，直接为筹备组且无需投票
        if (nowDate.getTime() < startDate.getTime()) {
            cdo.set("errorMsg", "报名未开始");
            return cdo;
        }
        if (nowDate.getTime() > endDate.getTime()) {
            //报名时间在设置时间之后，直接为筹备组且无需投票
            cdo.set("preparation_status", 1);
            //查询筹备组是否已经满员
            Integer preparations_number = voteInfo.getInteger("preparations_number");
            preparations_number = preparations_number != null ? preparations_number : 0;
            CDO select = new CDO();
            select.set("essential_information_id", voteInfo.getString("id"));
            select.set("preparation_status", 1);
            int total = voteEssentialInformationDao.getVoteUserListByCDOTotal(select);
            if (total >= preparations_number) {
                //筹备组人满了，为已报名但不属于筹备组
//                cdo.set("errorMsg","报名失败，筹备组人员已满");
//                return cdo;
                cdo.set("preparation_status", 0);
            }
//            if(total+1 == preparations_number){
//                //人满了，报名结束
//                //筹备组招募公示
//                CDO record = new CDO();
//                record.set("essential_information_id", voteUserInfo.getString("essential_information_id"));
//                record.set("vote_type", 1);
//                CDO recordInfo = voteRecordDao.getVoteRecordByCdo(record);
//                if(recordInfo == null) {
//                    cdo.set("errorMsg","活动信息异常，请联系管理员");
//                    return cdo;
//                }
//                CDO updateRecord = new CDO();
//                updateRecord.set("id",recordInfo.getString("id"));
//                updateRecord.set("update_time",sdf.format(new Date()));
//                updateRecord.set("vote_state",1);//1.结束 0.进行中
//                voteRecordDao.updateVoteRecordById(updateRecord);
//            }
        }
        return cdo;
    }

    /**
     * 获取报名状态
     *
     * @return
     */
    @OpenApi
    public Return getApplicationState(CDO cdoRequest) {
        //公示id
        String id = cdoRequest.getString("id");
        if (StringUtils.isEmpty(id)) return Return.valueOf(-2, "公示id不可为空");
        //操纵人
        String user_id = cdoRequest.getString("user_id");
        if (StringUtils.isEmpty(user_id)) return Return.valueOf(-2, "user_id不可为空");
        CDO publicityInfo = voteEssentialInformationDao.getPublicityById(id);
        if (publicityInfo == null) Return.valueOf(-2, "公示信息异常，请联系客服");
        //返回该人在此表决的角色信息
        CDO publicCount = new CDO();
        publicCount.set("essential_information_id", publicityInfo.getString("essential_information_id"));
        publicCount.set("user_id", user_id);
        CDO voteUserInfo = voteUserDao.getVoteUserInfoByCDO(publicCount);
        return Return.valueOf(voteUserInfo);
    }

    /**
     * 业主端公示列表查询
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return getOwnerAppPublicityListById(CDO cdoRequest) {
        //表决主键id
        String id = cdoRequest.getString("id");
        String user_id = cdoRequest.getString("user_id");
        if (StringUtils.isEmpty(id)) return Return.valueOf(-2, "表决id不可为空");
        List<CDO> publicityList = voteEssentialInformationDao.getPublicityListById(id);
        for (CDO publicityInfo : publicityList) {
            String recordId = publicityInfo.getString("id");
            Integer selectTotal = 0;
            if (!StringUtils.isEmpty(user_id)) {
                CDO selectRedDots = new CDO();
                selectRedDots.set("p_id", recordId);
                selectRedDots.set("user_id", user_id);
                selectTotal = voteEssentialInformationDao.getRedTotalByCDO(selectRedDots);
            }
            //0.无红点
            publicityInfo.set("redDotsSelectTotal", selectTotal);
        }
        return Return.valueOf(publicityList);
    }

    /**
     * 获取公示详细详细
     *
     * @return
     */
    @OpenApi
    public Return getPublicityDetailInfoById(CDO cdoRequest) {
        //公示id
        String id = cdoRequest.getString("id");
        if (StringUtils.isEmpty(id)) return Return.valueOf(-2, "公示id不可为空");
        CDO publicityInfo = voteEssentialInformationDao.getPublicityById(id);
        return Return.valueOf(publicityInfo);
    }

    /**
     * 查询公示状态
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return selectPublicityState(CDO cdoRequest) throws ParseException {
        //表决主键id
        String id = cdoRequest.getString("id");
        if (StringUtils.isEmpty(id)) return Return.valueOf(-2, "id不可为空");
        //1.筹备组招募公示  2.筹备组投票 3.筹备组成员公示 4.业主规约公示 5.委员招募公示 6.委员投票公示 9.委员信息公示
        Integer contentStatus = cdoRequest.getInteger("contentStatus");
        if (contentStatus == null) return Return.valueOf(-2, "公示类型不可为空");
        CDO select = new CDO();
        select.set("essential_information_id", id);
        select.set("vote_type", contentStatus);
        CDO recordInfo = voteRecordDao.getVoteRecordByCdo(select);
        if (recordInfo == null) {
            return Return.valueOf(recordInfo);
        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //是否可点击继续
        Boolean clickFlag = false;
        //3.筹备组成员公示 || 工作组成员公示
        if (contentStatus == 3) {
            //筹备组成员公示7天后即可点击继续至下一步
            Date begin_time = recordInfo.getDate("begin_time");
            //相差几分钟
            long time = this.getTime(sdf.format(begin_time), sdf.format(new Date()));
            //long time = this.getTime("2022-11-07 12:56:31", sdf.format(new Date()));
            if (time >= 10080) {
                clickFlag = true;
            }
            recordInfo.set("clickFlag", clickFlag);
        }
        //4.业主规约公示
        //2022-11-30，业主规约公示结束后可进行下一步
        if (contentStatus == 4) {
            CDO voteInfo = voteEssentialInformationDao.getVoteEssentialInformationById(recordInfo.getInteger("essential_information_id"));
            if (voteInfo != null) {
                //业主规约公示结束事件
                Date four_publicity_end_time = voteInfo.getDate("four_publicity_end_time");
                if (four_publicity_end_time != null) {
                    recordInfo.set("clickFlag", new Date().getTime() > four_publicity_end_time.getTime() ? true : false);
                }
            }
        }
        //5.委员招募公示 报名时间开始，展示公示中，报名
        if (contentStatus == 5) {
            CDO voteInfo = voteEssentialInformationDao.getVoteEssentialInformationById(recordInfo.getInteger("essential_information_id"));
            if (voteInfo != null) {
                //委员报名开始时间
                Date five_registration_time = voteInfo.getDate("five_registration_time");
                //是否可点击下一步
                if (five_registration_time != null) {
                    //开始时间小于当前时间
                    recordInfo.set("clickFlag", new Date().getTime() >= five_registration_time.getTime() ? true : false);
                }
            }
        }
        //6.委员投票公示，公示7天后可点击进行下一步
        if (contentStatus == 6) {
            Date begin_time = recordInfo.getDate("begin_time");
            //相差几分钟
            long time = this.getTime(sdf.format(begin_time), sdf.format(new Date()));
            if (time >= 10080) {
                clickFlag = true;
            }
            recordInfo.set("clickFlag", clickFlag);
        }
        //9.委员信息公示，公示7天后可点击进行下一步
        if (contentStatus == 9) {
            Date begin_time = recordInfo.getDate("begin_time");
            //相差几分钟
            long time = this.getTime(sdf.format(begin_time), sdf.format(new Date()));
            if (time >= 10080) {
                clickFlag = true;
            }
            recordInfo.set("clickFlag", clickFlag);
        }
        //12.业委会职位结果公示，公示7天后可点击进行下一步
        if (contentStatus == 12) {
            Date begin_time = recordInfo.getDate("begin_time");
            //相差几分钟
            long time = this.getTime(sdf.format(begin_time), sdf.format(new Date()));
            if (time >= 10080) {
                clickFlag = true;
            }
            recordInfo.set("clickFlag", clickFlag);
        }
        //22.选聘物业结果公示
        if (contentStatus == 22) {
            Date begin_time = recordInfo.getDate("begin_time");
            //相差几分钟
            long time = this.getTime(sdf.format(begin_time), sdf.format(new Date()));
            if (time >= 10080) {
                clickFlag = true;
            }
            recordInfo.set("clickFlag", clickFlag);
        }
        Date begin_time = recordInfo.getDate("begin_time");
        if (begin_time != null) {
            Calendar cal = Calendar.getInstance();
            cal.setTime(begin_time);
            cal.add(Calendar.DATE, +7);
            recordInfo.set("end_time", sdf.format(cal.getTime()));
        }
        //clickFlag 判断是否时间条件满足，按钮是否可点击，调试的时候默认可点击
        recordInfo.set("clickFlag", true);
        return Return.valueOf(recordInfo);
    }

    /**
     * 获取两个时间相差分钟数
     *
     * @param oldTime
     * @param newTime
     * @return
     * @throws ParseException
     */
    public static long getTime(String oldTime, String newTime) throws ParseException {

        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        long NTime = df.parse(newTime).getTime();
        //从对象中拿到时间
        long OTime = df.parse(oldTime).getTime();
        long diff = (NTime - OTime) / 1000 / 60;
        return diff;
    }

    /**
     * 发布招募报名公示
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return updatePublicityById(CDO cdoRequest) {
        //表决主键id
        String id = cdoRequest.getString("id");
        if (StringUtils.isEmpty(id)) return Return.valueOf(-2, "id不可为空");
        //1.筹备组招募公示 5.委员招募公示
        Integer contentStatus = cdoRequest.getInteger("contentStatus");
        if (contentStatus == null) return Return.valueOf(-2, "公示类型不可为空");
        String content = cdoRequest.getString("content");
        if (StringUtils.isEmpty(content)) return Return.valueOf(-2, "内容不可为空");
        String user_id = cdoRequest.getString("user_id");
        if (StringUtils.isEmpty(user_id)) return Return.valueOf(-2, "user_id不可为空");
        CDO voteInfo = voteEssentialInformationDao.getVoteEssentialInformationById(Integer.parseInt(id));
        if (voteInfo == null) {
            return Return.valueOf(-2, "表决信息异常");
        }
        //2023-5-22，新增解聘物业公示，工作组即为筹备组
        //表决类型：1.申请成立业主大会 2.解聘现物业公司 3.选聘物业公司
        Integer vote_type = voteInfo.getInteger("vote_type");

        //键名
        String keyName = contentStatus == 1 ? "preparations_vote_content"
                : contentStatus == 5 ? "five_recruit"
                : "hehe";
        //修改公示信息
        CDO update = new CDO();
        update.set("id", id);
        update.set(keyName, content);
        voteEssentialInformationDao.updateVoteEssentialInformationById(update);
        //公示名称
        String recordName = contentStatus == 1 ? "招募筹备组公示" : "未知";
        if (vote_type == 2 && contentStatus == 1) {
            recordName = "招募工作组公示";
        }
        if (vote_type == 3 && contentStatus == 1) {
            recordName = "招募工作组公示";
        }
        if (contentStatus == 5) {
            recordName = "招募委员公示";
        }
        if (contentStatus == 14) {
            recordName = "委托人招募公示";
        }
        if (contentStatus == 19) {
            recordName = "竞争性谈判小组招募公示";
        }
        //添加至公示记录表 vote_record
        CDO addVoteRecord = new CDO();
        addVoteRecord.set("user_id", user_id);
        addVoteRecord.set("essential_information_id", id);
        addVoteRecord.set("vote_name", recordName);
        addVoteRecord.set("vote_type", contentStatus);
        addVoteRecord.set("vote_state", 0);
        //公示内容
        addVoteRecord.set("contentL", content);
        this.addVoteRecord(addVoteRecord);
        return Return.valueOf(0, recordName + "成功！");
    }

    /**
     * 添加或修改筹备组人员信息
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return addOrUpdatePreparationUserInfo(CDO cdoRequest) {
        //姓名
        String full_name = cdoRequest.getString("full_name");
        //手机号
        String telephone = cdoRequest.getString("telephone");
        //单位
        String company = cdoRequest.getString("company");
        //判断手机号及姓名是否注册
        if (StringUtils.isEmpty(full_name)) return Return.valueOf(-2, "请填写姓名");
        if (StringUtils.isEmpty(telephone)) return Return.valueOf(-2, "请填写手机号");
        if (StringUtils.isEmpty(company)) return Return.valueOf(-2, "请填写单位");

        //修改
        String id = cdoRequest.getString("id");
        if (!StringUtils.isEmpty(id)) {
            CDO voteUserInfo = voteUserDao.getVoteUserById(Integer.parseInt(id));
            if (voteUserInfo == null) return Return.valueOf(-2, "人员数据异常，请联系客服");
            //编写筹备组标识参数
            CDO updateUserInfo = new CDO();
            updateUserInfo.set("user_id", voteUserInfo.getString("user_id"));
            updateUserInfo.set("essential_information_id", voteUserInfo.getString("essential_information_id"));
            updateUserInfo.set("company", company);
            this.publicAdditionsAddOrUpdateVoteUser(updateUserInfo);
            return Return.valueOf(0, "修改筹备组组员成功！");
        }

        //校验组长是否为助业网用户
        String user_id = this.getUserIdByUserNameAndTel(full_name, telephone);
        if (StringUtils.isEmpty(user_id)) return Return.valueOf(-2, "筹备组成员必须是助业网会员");
        //查询手动添加的筹备组是否超过限制
        String voteId = cdoRequest.getString("essential_information_id");
        if (StringUtils.isEmpty(voteId)) return Return.valueOf(-2, "表决id不可为空");
        CDO voteInfo = voteEssentialInformationDao.getVoteEssentialInformationById(Integer.parseInt(voteId));
        if (voteInfo == null) return Return.valueOf(-2, "表决信息异常");
        //用户设置的筹备组人员数量
        Integer preparations_number = voteInfo.getInteger("preparations_number");
        //addMax 可手动添加的最大数量
        Integer addMax = preparations_number / 2;
        //查询非业主的筹备组数量
        CDO select = new CDO();
        select.set("essential_information_id", voteId);
        Integer preparatoryGroupTotal = voteEssentialInformationDao.getPreparatoryGroupTotal(select);
        preparatoryGroupTotal = preparatoryGroupTotal == null ? 0 : preparatoryGroupTotal;
        if (preparatoryGroupTotal >= addMax) {
            return Return.valueOf(-2, "手动添加筹备组成员人数上限");
        }
        //查询该人在此表决中是否在报名或已为筹备组成员
        select.set("user_id", user_id);
        Integer userTotal = voteEssentialInformationDao.verifyPreparatoryGroupTotal(select);
        if (userTotal > 0) return Return.valueOf(-2, "该人已报名或已为筹备组成员");
        CDO addUserInfo = new CDO();
        addUserInfo.set("user_id", user_id);
        addUserInfo.set("user_id_zyw", user_id);
        addUserInfo.set("essential_information_id", voteId);
        addUserInfo.set("full_name", full_name);
        addUserInfo.set("telephone", telephone);
        addUserInfo.set("company", company);
        addUserInfo.set("preparation_status", 1);//是否筹备组成员：1是，0否
        addUserInfo.set("perparation_add_state", 1);//1.手动添加
        addUserInfo.set("house_name", voteInfo.getString("community_name"));//小区名称  无意义参数
        this.publicAdditionsAddOrUpdateVoteUser(addUserInfo);
        return Return.valueOf(0, "添加筹备组组员成功！");
    }


    /**
     * 修改投票用户信息，附议
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return updateVoteUserInfo(CDO cdoRequest) {
        Integer voteType = cdoRequest.getInteger("voteType");
        voteType = voteType != null ? voteType : 0;
        if (voteType == 1) {
            //记录附议时间
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            cdoRequest.set("reconsideration_time", sdf.format(new Date()));
        }
        CDO voteUserInfo = voteUserDao.getVoteUserById(cdoRequest.getInteger("id"));
        voteUserDao.updateVoteUserById(cdoRequest);
        if (voteType == 1) {
            //判断附议是否自动通过
            this.secondedAutoPass(voteUserInfo.getString("essential_information_id"));
        }
        return Return.SUCCESS;
    }


    /**
     * 附议是否自动通过
     *
     * @return
     */
    @OpenApi
    public Return secondedWhetherAutoPass(CDO cdoRequest) {
        String id = cdoRequest.getString("id");
        if (StringUtils.isEmpty(id)) return Return.valueOf(-2, "id不可为空");
        Boolean passFlag = this.secondedAutoPass(id);
        return Return.valueOf(passFlag);
    }

    /**
     * 附议是否自动通过
     *
     * @return
     */
    public Boolean secondedAutoPass(String vote_id) {
        CDO voteSetInfo = voteEssentialInformationDao.getVoteSecondedInfoByVoteId(vote_id);
        //标准  1.两项都满足 2.满足一项 3.满足人数 4.满足面积
        Integer set_status = voteSetInfo.getInteger("set_status");
        //自动通过数量
        Integer user_room = voteSetInfo.getInteger("user_room");
        user_room = user_room == null ? 0 : user_room;
        //自动通过面积
        Double user_area = voteSetInfo.getDouble("user_area");
        user_area = user_area == null ? 0 : user_area;

        //附议人数
        Integer secondedTotal = voteEssentialInformationDao.getNumberOfSecondedProposalsTotal(vote_id);
        secondedTotal = secondedTotal != null ? secondedTotal : 0;
        //附议面积
        Double areSum = voteEssentialInformationDao.getNumberOfSecondedProposalsAreaSum(vote_id);
        areSum = areSum != null ? areSum : 0;
        //面积没达到用户标准
        if (set_status != 3 && areSum < user_area) return false;
        //数量是否达到
        if (set_status != 4 && secondedTotal < user_room) return false;
        //2023-6-1,解聘物业，委员身份不可自动结束附议

        //结束附议
        this.endSecondedInfoById(voteSetInfo.getString("id"));
        return true;
    }

    /**
     * 根据表决主键id和user_id查询本表决的用户信息
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return getVoteUserInfoByUserIdAndVoteId(CDO cdoRequest) {
        String user_id = cdoRequest.getString("user_id");//操作人
        String vote_id = cdoRequest.getString("vote_id");//表决主键id
        if (StringUtils.isEmpty(user_id)) return Return.valueOf(-2, "请先登录");
        if (StringUtils.isEmpty(vote_id)) return Return.valueOf(-2, "vote_id不可为空");
        CDO voteUserInfo = voteEssentialInformationDao.getVoteUserInfoByVoeIdAndUserId(user_id, vote_id);
        return Return.valueOf(voteUserInfo);
    }

    /**
     * 业主端根据id查询表决投票类型
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return getOwnerAppVoteTypeById(CDO cdoRequest) {
        String id = cdoRequest.getString("id");
        if (StringUtils.isEmpty(id)) return Return.valueOf(-2, "id不可为空");
        //到第几大步，第几小步
        CDO stepInfo = this.getStepInfoById(id);
        //大步
        Integer bigStep = stepInfo.getInteger("voteType");
        //小步
        Integer smallStep = stepInfo.getInteger("curStep");

        CDO voteInfo = voteEssentialInformationDao.getVoteEssentialInformationById(Integer.parseInt(id));
        if (voteInfo == null) return Return.valueOf(-2, "表决信息异常");
        //表决类型：1.申请成立业主大会 2.解聘现物业公司 3.选聘物业
        Integer vote_type = voteInfo.getInteger("vote_type");
        Integer voteType = null;
        if (vote_type == 1) {
            if (bigStep == 2 && smallStep == 2) {
                voteType = 1;//附议
            }
            if (bigStep == 3 && smallStep == 3) {
                //筹备组投票
                voteType = 2;
            }
            if (bigStep == 7 && smallStep == 1) {
                //委员投票
                voteType = 3;
            }
            if (bigStep == 8 && smallStep == 2) {
                //主任投票
                voteType = 4;
            }
            if (bigStep == 8 && smallStep == 4) {
                //副主任投票
                voteType = 5;
            }
        }
        //2023-5-22，解聘物业，工作组成员投票
        if (vote_type == 2) {
            if (bigStep == 2 && smallStep == 2) {
                voteType = 1;//附议
            }
            if (bigStep == 2 && smallStep == 3) {
                //筹备组投票 即为 工作组投票
                voteType = 2;
            }
            if (bigStep == 2 && smallStep == 7) {
                //筹备组投票 即为 工作组投票
                voteType = 2;
            }
            if (bigStep == 3 && smallStep == 3) {
                //委托人投票
                voteType = 7;
            }
            if (bigStep == 5 && smallStep == 1) {
                //解聘物业业主大会投票
                voteType = 8;
            }
        }
        //2023-6-19，选聘物业
        if (vote_type == 3) {
            if (bigStep == 2 && smallStep == 2) {
                voteType = 1;//附议
            }
            if (bigStep == 2 && smallStep == 3) {
                //工作组投票
                voteType = 2;
            }
            if (bigStep == 2 && smallStep == 7) {
                //工作组投票
                voteType = 2;
            }
            if (bigStep == 2 && smallStep == 9) {
                voteType = 6;//工作组组长投票
            }
            CDO selectRecord = new CDO();
            selectRecord.set("essential_information_id", id);
            selectRecord.set("vote_type", 20);
            selectRecord.set("vote_state", 0);
            CDO voteRecordInfo = voteEssentialInformationDao.getVoteRecordInfoByCDO(selectRecord);
            if (voteRecordInfo != null) {
                voteType = 9;//谈判小组业主投票
            }
            if (bigStep == 4 && smallStep == 2) {
                voteType = 10;//物业公司选聘
            }
            if (bigStep == 5) {
                voteType = 10;//物业公司选聘
            }
        }

//        voteType = 4;
        return Return.valueOf(voteType);
    }

    /**
     * 查询操作人是否为本表决筹备组组长
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return getOperatePermissionsByPreparation(CDO cdoRequest) {
        //表决主键id
        String id = cdoRequest.getString("id");
        if (StringUtils.isEmpty(id)) return Return.valueOf(-2, "id不可为空");
        CDO voteInfo = voteEssentialInformationDao.getVoteEssentialInformationById(Integer.parseInt(id));
        if (voteInfo == null) return Return.valueOf(-2, "表决信息异常，请联系管理员");
        String user_id = cdoRequest.getString("user_id");//操作人
        if (StringUtils.isEmpty(user_id)) return Return.valueOf(-2, "user_id不可为空");
        CDO select = new CDO();
        select.set("user_id", user_id);
        select.set("essential_information_id", id);
        CDO leaderInfo = voteEssentialInformationDao.getVotePreparationLeader(select);
        //可直接拿 vote_essential_information 的 preparation_vote_user_id 进行比较，后来才发现这个字段
        return Return.valueOf(leaderInfo != null ? 1 : 0);
    }

    /**
     * 三大步 确认组长，组长填写信息，继续
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return confirmPreparationLeader(CDO cdoRequest) {
        //表决主键id
        String id = cdoRequest.getString("id");
        if (StringUtils.isEmpty(id)) return Return.valueOf(-2, "id不可为空");
        CDO voteInfo = voteEssentialInformationDao.getVoteEssentialInformationById(Integer.parseInt(id));
        if (voteInfo == null) return Return.valueOf(-2, "表决信息异常，请联系管理员");

        String user_id = cdoRequest.getString("userId");//操作人
        if (StringUtils.isEmpty(user_id)) return Return.valueOf(-2, "user_id不可为空");

        //成立筹备组第几小步
        //1.确认组长 2.组长确认信息 3.继续
        Integer step = cdoRequest.getInteger("step");
        if (step == null) return Return.valueOf(-2, "step不可为空");
        String preparation_name = cdoRequest.getString("preparation_name");//组长姓名
        String preparation_telephone = cdoRequest.getString("preparation_telephone");//组长手机号
        String preparation_company = cdoRequest.getString("preparation_company");//组长所在单位
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String leaderUserId = null;//组长userId
        if (step == 1) {
            if (StringUtils.isEmpty(preparation_name) || StringUtils.isEmpty(preparation_telephone) || StringUtils.isEmpty(preparation_company)) {
                return Return.valueOf(-2, "筹备组组长参数缺失");
            }
            //校验组长是否为助业网用户
            leaderUserId = this.getUserIdByUserNameAndTel(preparation_name, preparation_telephone);
            if (StringUtils.isEmpty(leaderUserId)) {
                return Return.valueOf(-2, "筹备组组长必须是助业网会员");
            }
            //筹备组组长userid
            cdoRequest.set("preparation_vote_user_id", leaderUserId);
            cdoRequest.set("preparation_status", 1);//1.有筹备组组长
            //发个系统消息给组长
            //String remark = voteInfo.getString("community_name") + "申请成立业主大会，选择您为筹备组组长，请登录助业网进行下一步确认小区及招募信息操作。";
            String remark = "尊敬的" + preparation_name + "，您已为" + voteInfo.getString("community_name") + "筹备组组长，请使用电脑登录助业投票表决平台（www.515f.com或下载助业App）进行操作";
            this.addMessageInfo(remark, leaderUserId, 1);
            //添加筹募组组长信息至vote_user
            CDO addVoteUserInfo = new CDO();
            addVoteUserInfo.set("user_id", leaderUserId);
            addVoteUserInfo.set("user_id_zyw", leaderUserId);
            addVoteUserInfo.set("essential_information_id", id);
            addVoteUserInfo.set("full_name", preparation_name);
            addVoteUserInfo.set("telephone", preparation_telephone);
            addVoteUserInfo.set("company", preparation_company);
            addVoteUserInfo.set("preparation_status", 1);//1.是筹备组成员
            addVoteUserInfo.set("preparation_state", 1);//0.成员  1.组长
            addVoteUserInfo.set("perparation_add_state", 1);//添加状态 1.手动添加
            this.publicAdditionsAddOrUpdateVoteUser(addVoteUserInfo);
        }
        if (step == 2) {
            SimpleDateFormat simple = new SimpleDateFormat("yyyy-MM-dd");
            String nowTimeStr = simple.format(new Date());
            //确认业主人数
            String household_total = cdoRequest.getString("household_total");
            if (StringUtils.isEmpty(household_total)) return Return.valueOf(-2, "请填写业主人数");
            //确认面积
            String community_areass = cdoRequest.getString("community_areass");
            if (StringUtils.isEmpty(community_areass)) return Return.valueOf(-2, "请填写面积");
            //确认筹备组人数
            String preparations_number = cdoRequest.getString("preparations_number");
            if (StringUtils.isEmpty(preparations_number)) return Return.valueOf(-2, "请选择筹备组人数");
            //报名时间
            String preparations_start_time = cdoRequest.getString("preparations_start_time");
            String preparations_end_time = cdoRequest.getString("preparations_end_time");
            if (StringUtils.isEmpty(preparations_start_time) || StringUtils.isEmpty(preparations_end_time))
                return Return.valueOf(-2, "请选择报名时间");
            //投票时间
            String preparations_vote_start_time = cdoRequest.getString("preparations_vote_start_time");
            String preparations_vote_end_time = cdoRequest.getString("preparations_vote_end_time");
            if (StringUtils.isEmpty(preparations_vote_start_time) || StringUtils.isEmpty(preparations_vote_end_time))
                return Return.valueOf(-2, "请选择投票时间");
            //报名开始时间不可小于当天时间，且时间周期至少为1天
            Integer nowToStart = this.getTwoTimeDiffDay(nowTimeStr, preparations_start_time);
            if (nowToStart < 0) return Return.valueOf(-2, "报名开始时间不可低于当天时间");
            Integer startToEnd = this.getTwoTimeDiffDay(preparations_start_time, preparations_end_time);
            if (startToEnd < 1) return Return.valueOf(-2, "报名时间周期至少为1天");
            //投票开始时间不可小于报名结束时间，且时间周期至少为7天  投票开始直接说周期至少为1天
            Integer voteTime = this.getTwoTimeDiffDay(preparations_end_time, preparations_vote_start_time);
            if (voteTime < 7) return Return.valueOf(-2, "投票开始时间必须在报名结束时间之后7天");
            Integer voteTime2 = this.getTwoTimeDiffDay(preparations_vote_start_time, preparations_vote_end_time);
            if (voteTime2 < 1) return Return.valueOf(-2, "投票时间周期至少为1天");
        }
        if (step == 3) {
            //修改筹备组成员公示结束
            CDO record = new CDO();
            record.set("essential_information_id", id);
            record.set("vote_type", 3);
            CDO recordInfo = voteRecordDao.getVoteRecordByCdo(record);
            if (recordInfo == null) return Return.valueOf(-2, "筹备组成员公示信息异常，请联系客服");
            CDO updateRecord = new CDO();
            updateRecord.set("id", recordInfo.getString("id"));
            updateRecord.set("vote_state", 1);//1.结束 0.进行中
            voteRecordDao.updateVoteRecordById(updateRecord);
        }

        //修改表决信息
        voteEssentialInformationDao.updateVoteEssentialInformationById(cdoRequest);

        String remark = "";
        Integer bigStep = 3;
        Integer smallStep = 1;
        if (step == 1) {
            remark = "上传组长信息时间：";
            smallStep = 2;
        }
        if (step == 2) {
            remark = "确认组长信息时间：";
            smallStep = 3;
        }
        if (step == 3) {
            //跳转至下一大步
            bigStep = 4;
            remark = "筹备组继续下一步时间：";
            smallStep = 1;
        }

        //添加步骤
        CDO addVoteStep = new CDO();
        addVoteStep.set("step_id", id);//关联id
        addVoteStep.set("user_id", user_id);//发起人才可结束附议
        addVoteStep.set("property", voteInfo.getString("community_name"));
        //数据备注

        addVoteStep.set("planned_speed", remark + sdf.format(new Date()));
        addVoteStep.set("complete_state", 1);
        //到第几大步
        addVoteStep.set("step_big", bigStep);
        //到第几小步
        addVoteStep.set("step_small", smallStep);
        this.publicAdditionsAddVoteStep(addVoteStep);
        return Return.SUCCESS;
    }

    /**
     * 获取俩时间相差多少天
     *
     * @param beginTimeStr
     * @param endTimeStr
     * @return
     */
    public Integer getTwoTimeDiffDay(String beginTimeStr, String endTimeStr) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        long diff = 0;
        try {
            diff = sdf.parse(endTimeStr).getTime() - sdf.parse(beginTimeStr).getTime();
        } catch (Exception e) {
            return -1;
        }
        if (diff < 0) {
            return -1;
        }
        //一天的毫秒数
        long nd = 1000 * 60 * 60 * 24;
        Long sec = diff / nd;
        sec = sec == null ? 0L : sec;
        return Integer.parseInt(sec.toString());
    }


    /**
     * @param messageText 消息内容
     * @param user_id     接受人
     * @param type        1.助业网 2.员工端 3.业主端
     */
    public void addMessageInfo(String messageText, String user_id, Integer type) {
        if (StringUtils.isEmpty(messageText) || StringUtils.isEmpty(user_id) || type == null) return;
        CDO addMessage = new CDO();
        addMessage.set("user_id", 1);//1.助业官方账号
        addMessage.set("by_user_id", user_id);//接受人
        addMessage.set("message", messageText);//内容
        if (type == 1) {
            voteEssentialInformationDao.addZhuYeMessage(addMessage);
        } else {
            voteEssentialInformationDao.addOwnerMessage(addMessage);
        }
    }

    /**
     * 根据用户名称和手机号获取用户id
     *
     * @param userName
     * @param userTel
     * @return
     */
    public String getUserIdByUserNameAndTel(String userName, String userTel) {
        if (StringUtils.isEmpty(userName) || StringUtils.isEmpty(userTel)) return null;
        String user_id = voteEssentialInformationDao.getUserIdByNameAndTel(userName, userTel);
        return StringUtils.isEmpty(user_id) ? null : user_id;
    }


    /**
     * 重新提交申请表，需改步骤为 2 4
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return goBackToApply(CDO cdoRequest) {
        //表决主键id
        String essential_information_id = cdoRequest.getString("essential_information_id");
        if (StringUtils.isEmpty(essential_information_id)) return Return.valueOf(-2, "essential_information_id不可为空");
        CDO voteInfo = voteEssentialInformationDao.getVoteEssentialInformationById(Integer.parseInt(essential_information_id));
        if (voteInfo == null) return Return.valueOf(-2, "表决信息异常，请联系管理员");
        //表决主键id
        String user_id = cdoRequest.getString("user_id");
        if (StringUtils.isEmpty(user_id)) return Return.valueOf(-2, "user_id不可为空");
        //添加步骤
        CDO addVoteStep = new CDO();
        addVoteStep.set("step_id", essential_information_id);//关联id
        addVoteStep.set("user_id", user_id);//发起人才可结束附议
        addVoteStep.set("property", voteInfo.getString("community_name"));
        //数据备注
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        addVoteStep.set("planned_speed", "重新提交申请表时间：" + sdf.format(new Date()));
        addVoteStep.set("complete_state", 1);
        //到第2大步
        addVoteStep.set("step_big", 2);
        //到第几小步
        addVoteStep.set("step_small", 4);
        this.publicAdditionsAddVoteStep(addVoteStep);
        return Return.SUCCESS;
    }

    /**
     * 递交申请表申请
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return addOrUpdateSubmitApplyFrom(CDO cdoRequest) {
        //表决主键id
        String essential_information_id = cdoRequest.getString("essential_information_id");
        if (StringUtils.isEmpty(essential_information_id)) return Return.valueOf(-2, "essential_information_id不可为空");
        CDO voteInfo = voteEssentialInformationDao.getVoteEssentialInformationById(Integer.parseInt(essential_information_id));
        if (voteInfo == null) return Return.valueOf(-2, "表决信息异常，请联系管理员");
        //表决主键id
        String user_id = cdoRequest.getString("user_id");
        if (StringUtils.isEmpty(user_id)) return Return.valueOf(-2, "user_id不可为空");
        //递交申请表的第几步
        String small_step = cdoRequest.getString("small_step");
        if (StringUtils.isEmpty(small_step)) return Return.valueOf(-2, "small_step不可为空");

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String audit_status = cdoRequest.getString("audit_status");//批复结果  0、审核中，1、审核成功，2、审核失败
        if (small_step.equals("2") && StringUtils.isEmpty(audit_status)) return Return.valueOf(-2, "请选择批复结果");
        //查询判断添加还是修改
        CDO voteRecons = new CDO();
        voteRecons.set("essential_information_id", essential_information_id);
        CDO voteReconsideration = voteReconsiderationDao.getVoteReconsideration(voteRecons);
        String msg = "添加成功";
        if (voteReconsideration != null) {
            msg = "修改成功";
            //修改
            cdoRequest.set("id", voteReconsideration.getString("id"));
            voteReconsiderationDao.updateVoteReconsiderationById(cdoRequest);
        } else {
            //添加
            voteReconsiderationDao.addVoteReconsideration(cdoRequest);
        }
        String remark = "";
        //大步
        Integer step_big = 2;
        //小步
        Integer step_small = 4;
        if (small_step.equals("1")) {
            remark = "提交申请表时间：";
            step_small = 5;
        }
        if (small_step.equals("2")) {
            //第二步 成功直接跳第三大步筹募组，失败跳第3小步 当前页面步骤 6
            remark = "上传批复文件时间：";
            step_big = audit_status.equals("1") ? 3 : 2;
            step_small = audit_status.equals("1") ? 1 : 6;
        }
        if (small_step.equals("3")) {
            //第3步 直接跳第三大步筹募组
            remark = "上传批复文件时间：";
            step_big = 3;
            step_small = 1;
        }

        //2023-5-22，新增
        if (small_step.equals("4")) {
            //第3步 直接跳第三大步筹募组
            remark = "上传批复文件时间：";
            step_big = 2;
            step_small = 6;
        }

        //添加步骤
        CDO addVoteStep = new CDO();
        addVoteStep.set("step_id", essential_information_id);//关联id
        addVoteStep.set("user_id", user_id);//发起人才可结束附议
        addVoteStep.set("property", voteInfo.getString("community_name"));
        //数据备注
        addVoteStep.set("planned_speed", remark + sdf.format(new Date()));
        addVoteStep.set("complete_state", 1);
        //到第2大步
        addVoteStep.set("step_big", step_big);
        //到第几小步
        addVoteStep.set("step_small", step_small);
        this.publicAdditionsAddVoteStep(addVoteStep);
        return Return.valueOf(0, msg);
    }

    /**
     * 手动结束附议
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return manualEndSecondedInfo(CDO cdoRequest) {
        //vote_voting_seconded 主键id
        String id = cdoRequest.getString("id");
        if (StringUtils.isEmpty(id)){
            return Return.valueOf(-2, "id不可为空");
        }
        Object uuidObject = redisTemplate.get("");
        if(uuidObject == null){
            return Return.valueOf(-2, "请登录");
        }
        String uuid = uuidObject.toString();

        //前端做校验了，后端可以不加,便于线下测试
        this.endSecondedInfoById(id);
        return Return.SUCCESS;
    }

    /**
     * 结束附议
     */
    public void endSecondedInfoById(String id) {
        //id：vote_voting_seconded 主键id
        if (StringUtils.isEmpty(id)) return;
        //修改vote_record  vote_voting_seconded 字段
        CDO voteSecondedInfo = voteEssentialInformationDao.getVoteSecondedInfoById(id);
        if (voteSecondedInfo == null) return;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        //表决id
        String vote_id = voteSecondedInfo.getString("vote_id");
        CDO selectVoteRecord = new CDO();
        selectVoteRecord.set("essential_information_id", vote_id);
        selectVoteRecord.set("vote_type", 0);
        CDO recordInfo = voteEssentialInformationDao.getVoteRecordInfoByCDO(selectVoteRecord);
        if (recordInfo != null) {
            CDO updateRecord = new CDO();
            updateRecord.set("id", recordInfo.getString("id"));
            updateRecord.set("vote_state", 1);//结束
            updateRecord.set("update_time", sdf.format(new Date()));
            voteRecordDao.updateVoteRecordById(updateRecord);
        }
        CDO updateSecondedInfo = new CDO();
        updateSecondedInfo.set("id", id);
        updateSecondedInfo.set("state", 1);//结束
        updateSecondedInfo.set("update_time", sdf.format(new Date()));
        voteEssentialInformationDao.endSecondedById(updateSecondedInfo);
        //添加成立进度记录
        CDO voteInfo = voteEssentialInformationDao.getVoteEssentialInformationById(Integer.parseInt(vote_id));
        CDO addVoteStep = new CDO();
        addVoteStep.set("step_id", vote_id);//关联id
        addVoteStep.set("user_id", voteSecondedInfo.getString("user_id"));//发起人才可结束附议
        addVoteStep.set("property", voteInfo.getString("community_name"));
        //数据备注
        addVoteStep.set("planned_speed", "结束附议时间：" + sdf.format(new Date()));
        addVoteStep.set("complete_state", 1);
        //到第2大步
        addVoteStep.set("step_big", 2);
        //到第4小步
        addVoteStep.set("step_small", 4);
        this.publicAdditionsAddVoteStep(addVoteStep);
    }

    /**
     * 恢复或取消认证信息
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return cancelOrRecoverInfoById(CDO cdoRequest) {
        String id = cdoRequest.getString("id");
        if (StringUtils.isEmpty(id)) return Return.valueOf(-2, "id不可为空");
        //认证状态：0、认证正常，1、取消认证
        String audit_status = cdoRequest.getString("audit_status");
        if (StringUtils.isEmpty(audit_status)) return Return.valueOf(-2, "audit_status不可为空");
        //取消原因
        String audit_content = cdoRequest.getString("audit_content");
        if (audit_status.equals("1") && StringUtils.isEmpty(audit_content)) {
            return Return.valueOf(-2, "请填写取消认证原因");
        }
        CDO update = new CDO();
        update.set("id", id);
        update.set("audit_status", audit_status);
        update.set("audit_content", audit_content);
        voteEssentialInformationDao.cancelOrRecoverVoteUserInfoById(update);
        return Return.valueOf(0, audit_status.equals("0") ? "恢复认证" : "取消认证" + "成功！");
    }


    /**
     * 获取附议||认证记录列表 || 筹备组
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return getSecondRecordOrAuthenticationList(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex") - 1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> voteUserList = voteEssentialInformationDao.getVoteUserListByCDO(cdoRequest);
        for (CDO userInfo : voteUserList) {
            //身份证
            String user_card_code = userInfo.getString("user_card_code");
            if (!StringUtils.isEmpty(user_card_code)) {
                Map<String, String> birAgeSex = userCardInfoUtil.getBirAgeSex(user_card_code);
                userInfo.set("birthday", birAgeSex.get("birthday"));//出生日期
                userInfo.set("age", birAgeSex.get("age"));//年龄
                userInfo.set("sexCode", birAgeSex.get("sexCode"));//性别
            }
        }
        boolean isEndPage = false;
        if (voteUserList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", voteUserList);
        int total = voteEssentialInformationDao.getVoteUserListByCDOTotal(cdoRequest);
        cdoResult.set("total", total);
        //委员报名列表多返回个已报名且有资格的人数
        String selectMember = cdoRequest.getString("selectMember");
        if (!StringUtils.isEmpty(selectMember)) {
            cdoRequest.set("normalMember", 1);
            cdoResult.set("normalMemberTotal", voteEssentialInformationDao.getVoteUserListByCDOTotal(cdoRequest));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 编辑自动结束标准
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return updateAutoEndInfo(CDO cdoRequest) {
        //主键id
        String secondedId = cdoRequest.getString("secondedId");
        if (StringUtils.isEmpty(secondedId)) return Return.valueOf(-2, "secondedId不可为空");
        //填写户数
        String secondedRoom = cdoRequest.getString("secondedRoom");
        //填写户数
        String secondedArea = cdoRequest.getString("secondedArea");
        //标准  1.两项都满足 2.满足一项 3.满足人数 4.满足面积
        String set_status = cdoRequest.getString("set_status");
        if (StringUtils.isEmpty(set_status)) return Return.valueOf(-2, "set_status不可为空");

        //当前的最低户数标准
        String room_standard = cdoRequest.getString("room_standard");
        //当前的最低面积标准
        String area_standard = cdoRequest.getString("area_standard");
        //修改最新的标准及自动结束条件存进数据库
        CDO update = new CDO();
        update.set("id", secondedId);
        update.set("user_room", secondedRoom);
        update.set("user_area", secondedArea);
        update.set("set_room", room_standard);
        update.set("set_area", area_standard);
        update.set("set_status", set_status);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        update.set("update_time", sdf.format(new Date()));
        voteEssentialInformationDao.updateAutoEndInfoById(update);
        return Return.SUCCESS;
    }


    /**
     * 添加表决 第一步
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return oneAddVoteEssentialInformation(CDO cdoRequest) {
        Long user_id = cdoRequest.getLong("user_id");
        if (user_id == null) return Return.valueOf(-2, "用户信息异常，请重新登录");
        boolean userFlag = voteUserService.verifyWhetherSysUser(user_id);
        if (!userFlag) return Return.valueOf(-2, "用户信息异常，请重新登录");
        //小区名称
        String community_name = cdoRequest.getString("community_name");
        if (StringUtils.isEmpty(community_name)) return Return.valueOf(-2, "请填写小区名称");
        //校验该小区是否正在成立业委会
        CDO verify = new CDO();
        verify.set("community_name", cdoRequest.getString("community_name"));
        verify.set("vote_type", cdoRequest.getInteger("vote_type") == null ? 1 : cdoRequest.getInteger("vote_type"));
        verify.set("state", 0);
        int verifyTotal = voteEssentialInformationDao.getVoteEssentialInformationListByConditionCount(verify);
        if (verifyTotal > 0) return Return.valueOf(-2, "该小区已发起投票，请勿再次操作");
        //小区面积
        String community_areass = cdoRequest.getString("community_areass");
        if (StringUtils.isEmpty(community_areass)) return Return.valueOf(-2, "请填写小区面积");
        //小区户数
        String household_total = cdoRequest.getString("household_total");
        if (StringUtils.isEmpty(household_total)) return Return.valueOf(-2, "请填写小区户数");
        //省 市 区 详细位置
        String community_province = cdoRequest.getString("community_province");
        String community_city = cdoRequest.getString("community_city");
        String community_area = cdoRequest.getString("community_area");
        String community_position = cdoRequest.getString("community_position");
        if (StringUtils.isEmpty(community_province) || StringUtils.isEmpty(community_city) || StringUtils.isEmpty(community_area))
            return Return.valueOf(-2, "请选择小区位置");
        //小区面积凭证
        String community_voucher_img = cdoRequest.getString("community_voucher_img");
        if (StringUtils.isEmpty(community_voucher_img)) return Return.valueOf(-2, "请上传小区面积凭证");
        //发起人姓名
        String full_name = cdoRequest.getString("full_name");
        if (StringUtils.isEmpty(full_name)) return Return.valueOf(-2, "登录信息异常，请重新登录");
        //发起人手机号
        String telephone = cdoRequest.getString("telephone");
        if (StringUtils.isEmpty(telephone)) return Return.valueOf(-2, "请填写手机号");
        //发起人房间信息
        String one_district = cdoRequest.getString("one_district");
        String one_floor = cdoRequest.getString("one_floor");
        String one_unit = cdoRequest.getString("one_unit");
        String one_house_number = cdoRequest.getString("one_house_number");
//        if (StringUtils.isEmpty(one_district) || StringUtils.isEmpty(one_floor) || StringUtils.isEmpty(one_unit) || StringUtils.isEmpty(one_house_number))
//            return Return.valueOf(-2, "请填写房间信息");
        //发起人房间面积
        String one_area = cdoRequest.getString("one_area");
//        if (StringUtils.isEmpty(one_area)) return Return.valueOf(-2, "请填写房间面积");

        if (!StringUtils.isEmpty(one_district) && !StringUtils.isEmpty(one_floor) && !StringUtils.isEmpty(one_unit) && !StringUtils.isEmpty(one_house_number)) {
            cdoRequest.set("building_number", one_district + "-" + one_floor + "-" + one_unit + "-" + one_house_number);
        }
        //发起人身份证正反面 2023-5-12，身份证解聘第一步不必填
        String id_card_just = cdoRequest.getString("id_card_just");
        String id_card_back = cdoRequest.getString("id_card_back");
//        if (StringUtils.isEmpty(id_card_just) || StringUtils.isEmpty(id_card_back))
//            return Return.valueOf(-2, "请上传身份证正反面");
        //发起人房产证
        String house_certificate = cdoRequest.getString("house_certificate");
//        if (StringUtils.isEmpty(house_certificate)) return Return.valueOf(-2, "请上传房产证");
        voteEssentialInformationDao.addVoteEssentialInformation(cdoRequest);
        //主键id
        String id = cdoRequest.getString("id");
        //添加投票用户认证
        CDO addVoteUser = new CDO();
        addVoteUser.set("essential_information_id", id);//关联id
        addVoteUser.set("user_id", user_id);//用户id
        addVoteUser.set("user_id_zyw", user_id);//用户id
        addVoteUser.set("id_card_just", id_card_just);//身份证正面
        addVoteUser.set("id_card_back", id_card_back);//身份证反面
        addVoteUser.set("house_certificate", house_certificate);//房本图片
        addVoteUser.set("full_name", full_name);//姓名
        addVoteUser.set("telephone", telephone);//电话
        addVoteUser.set("building_number", cdoRequest.get("building_number"));//房间号
        addVoteUser.set("housing_area", one_area);//房间面积
        addVoteUser.set("house_name", community_name);//小区名称
        Return result =  this.publicAdditionsAddOrUpdateVoteUser(addVoteUser);

        String voteUserId = result.getData().getString("id");
        //添加成立进度记录
        CDO addVoteStep = new CDO();
        addVoteStep.set("step_id", id);//关联id
        addVoteStep.set("user_id", user_id);//发起人
        addVoteStep.set("property", community_name);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //数据备注
        addVoteStep.set("planned_speed", "填写基本信息时间：" + sdf.format(new Date()));
        addVoteStep.set("complete_state", 1);
        //到第几大步
        addVoteStep.set("step_big", 2);
        //到第几小步
        addVoteStep.set("step_small", 1);
        String voteStepId = this.publicAdditionsAddVoteStep(addVoteStep);
        cdoRequest.set("voteEssenid", id);//添加首次基本信息id
        cdoRequest.set("voteUserId", voteUserId);//添加投票用户认证
        cdoRequest.set("voteStepId", voteStepId);//添加成立进度记录
        //查询省市区信息
        List<CDO> positionList = voteEssentialInformationDao.getVoteAddressInformation(cdoRequest);
        cdoRequest.set("addressInfo", positionList);
        return Return.valueOf(cdoRequest.getInteger("id"));
    }

    /**
     * 添加表决进度
     *
     * @param addVoteStep
     * @return
     */
    @OpenApi
    public String publicAdditionsAddVoteStep(CDO addVoteStep) {
        voteStepDao.addVoteStep(addVoteStep);
        //关联本次投票步骤进度
        CDO updateVoteStepInfo = new CDO();
        updateVoteStepInfo.set("id", addVoteStep.getString("step_id"));
        updateVoteStepInfo.set("vote_step_id", addVoteStep.getString("id"));
        int i = voteEssentialInformationDao.updateVoteEssentialInformationById(updateVoteStepInfo);
        return addVoteStep.getString("id");
    }

    /**
     * 添加本次投票人员信息
     *
     * @param addVoteUser
     * @return
     */
    @OpenApi
    public Return publicAdditionsAddOrUpdateVoteUser(CDO addVoteUser) {
        CDO publicCount = new CDO();
        publicCount.set("essential_information_id", addVoteUser.getString("essential_information_id"));
        publicCount.set("user_id", addVoteUser.getString("user_id"));
        CDO voteUserInfo = voteUserDao.getVoteUserInfoByCDO(publicCount);
        if (voteUserInfo == null) {
            voteUserDao.addVoteUser(addVoteUser);
        } else {
            addVoteUser.set("id", voteUserInfo.getString("id"));
            voteUserDao.updateVoteUserById(addVoteUser);
        }
        return Return.valueOf(addVoteUser);
//        return addVoteUser.getString("id");
    }

    /**
     * 表决第二部确认发起附议
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return confirmTheInitiationOfTheProposal(CDO cdoRequest) {
        String user_id = cdoRequest.getString("user_id");
        if (StringUtils.isEmpty(user_id)) return Return.valueOf(-2, "user_id不可为空");
        String id = cdoRequest.getString("id");
        if (StringUtils.isEmpty(id)) return Return.valueOf(-2, "id不可为空");
        //后台设置标准主键id
        String setId = cdoRequest.getString("setId");
        if (StringUtils.isEmpty(setId)) return Return.valueOf(-2, "setId不可为空");
        //用户填写房间，面积数量
        String roomTotal = cdoRequest.getString("roomTotal");
        String areaTotal = cdoRequest.getString("areaTotal");
        roomTotal = StringUtils.isEmpty(roomTotal) ? "0" : roomTotal;
        areaTotal = StringUtils.isEmpty(areaTotal) ? "0" : areaTotal;
        CDO voteInfo = voteEssentialInformationDao.getVoteEssentialInformationById(Integer.parseInt(id));
        if (voteInfo == null) {
            return Return.valueOf(-2, "表决信息异常");
        }
        CDO setInfo = voteVotingSettingsDao.getVoteVotingSettingsById(Integer.parseInt(setId));
        if (setInfo == null) {
            return Return.valueOf(-2, "设置信息异常");
        }
        CDO passInfo = this.getPassConditionBySetInfoAndVoteInfo(voteInfo, setInfo);
        if (passInfo != null) {
            setInfo.set("passRoomTotal", passInfo.getString("passRoomTotal"));
            setInfo.set("passAreaTotal", passInfo.getString("passAreaTotal"));
        }
        //1.满足两项  2.满足一项 3.满足人数  4.满足面积
        String set_status = setInfo.getString("set_status");
        //最低通过标准
        Double passRoomTotal = setInfo.getDouble("passRoomTotal");
        Double passAreaTotal = setInfo.getDouble("passAreaTotal");

        //2023-5-15，解聘物业
        Integer vote_type = voteInfo.getInteger("vote_type");
        Double household_total = voteInfo.getDouble("household_total");
        Double community_areass = voteInfo.getDouble("community_areass");
        if (vote_type == 2) {
            //业主角色通过条件，面积：项目面积*0.2   附议户数：业主人数*0.2
            passRoomTotal = household_total * 0.2;
            passAreaTotal = community_areass * 0.2;
        }


        if (passRoomTotal == null && passAreaTotal == null) {
            return Return.valueOf(-2, "通过最低标准信息异常");
        }
        passRoomTotal = passRoomTotal != null ? passRoomTotal : 0;
        passAreaTotal = passAreaTotal != null ? passAreaTotal : 0;
        //1.业主 2.业委会委员
        Integer identity_type = voteInfo.getInteger("identity_type");
        identity_type = identity_type != null ? identity_type : 1;
        if (vote_type == 2 && identity_type == 2) {
            //解聘物业，委员身份不走判断

        } else {
            if (set_status.equals("1") || set_status.equals("2")) {
                //两项必填
                if (Integer.parseInt(roomTotal) < passRoomTotal) return Return.valueOf(-2, "附议业主人数不可低于最低标准");
                if (Integer.parseInt(areaTotal) < passAreaTotal) return Return.valueOf(-2, "附议面积不可低于最低标准");
            } else if (set_status.equals("3")) {
                //户数必填
                if (Integer.parseInt(roomTotal) < passRoomTotal) return Return.valueOf(-2, "附议业主人数不可低于最低标准");
            } else if (set_status.equals("4")) {
                //面积必填
                if (Integer.parseInt(areaTotal) < passAreaTotal) return Return.valueOf(-2, "附议面积不可低于最低标准");
            }
        }

        CDO addApplication = new CDO();
        addApplication.set("user_id", user_id);
        addApplication.set("vote_id", id);
        addApplication.set("set_id", setId);
        addApplication.set("user_room", roomTotal);
        addApplication.set("user_area", areaTotal);
        addApplication.set("set_room", passRoomTotal);
        addApplication.set("set_area", passAreaTotal);
        //逻辑不确定，按照当时发布时的标准 还是 按照最新的标准 进行附议是否完毕
        //存贮当时的设置数据至 set_old_info 可能有用
        addApplication.set("set_old_info", setInfo.toString());
        addApplication.set("set_status", set_status);
        voteVotingSettingsDao.addSecondedInfo(addApplication);
        //添加公示记录
        CDO addVoteRecord = new CDO();
        addVoteRecord.set("user_id", user_id);
        addVoteRecord.set("essential_information_id", id);
        addVoteRecord.set("vote_name", vote_type == 1 ? "成立业委会附议" : "解聘物业公司附议");
        addVoteRecord.set("vote_type", 0);
        String recordId = this.addVoteRecord(addVoteRecord);
        //添加确认发起附议记录
        CDO addVoteStep = new CDO();
        addVoteStep.set("step_id", id);//关联id
        addVoteStep.set("user_id", user_id);//发起人
        addVoteStep.set("property", voteInfo.getString("community_name"));
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //数据备注
        addVoteStep.set("planned_speed", "发起附议时间：" + sdf.format(new Date()));
        addVoteStep.set("complete_state", 1);
        //到第2大步
        addVoteStep.set("step_big", 2);
        //到第2小步
        addVoteStep.set("step_small", 2);
        String voteStepId = this.publicAdditionsAddVoteStep(addVoteStep);
        //修改vote_user表 发起人 附议状态为已附议
        CDO voteUserInfo = new CDO();
        voteUserInfo.set("user_id", user_id);
        voteUserInfo.set("essential_information_id", id);
        CDO voteUser = voteUserDao.getVoteUserInfoByCDO(voteUserInfo);
        if (voteUser != null) {
            CDO updateVoteUserInfo = new CDO();
            updateVoteUserInfo.set("update_time", sdf.format(new Date()));
            updateVoteUserInfo.set("reconsideration_status", 1);
            updateVoteUserInfo.set("id", voteUser.getString("id"));
            voteUserDao.updateUserInfoByCDO(updateVoteUserInfo);
        }
        return Return.SUCCESS;
    }

    /**
     * 添加公示记录
     *
     * @param cdo
     * @return
     */
    public String addVoteRecord(CDO cdo) {
        CDO select = new CDO();
        select.set("essential_information_id", cdo.getString("essential_information_id"));
        Integer vote_type = cdo.getInteger("vote_type");
        select.set("vote_type", vote_type);
        CDO recordInfo = voteRecordDao.getVoteRecordByCdo(select);
        if (vote_type == 10 || vote_type == 11) {
            //主任，副主任投票可进行无数次，保留记录
            recordInfo = null;
        }
        if (recordInfo == null) {
            voteRecordDao.addVoteRecord(cdo);
            return cdo.getString("id");
        }
        //修改
        voteRecordDao.updateVoteRecordById(cdo);
        return recordInfo.getString("id");
    }

    /**
     * 获取表决详细展示信息
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return getDetailInfoById(CDO cdoRequest) {
        String id = cdoRequest.getString("id");
        if (StringUtils.isEmpty(id)) return Return.valueOf(-2, "id不可为空");
        CDO voteInfo = voteEssentialInformationDao.getVoteEssentialInformationById(Integer.parseInt(id));
        if (voteInfo == null) {
            return Return.valueOf(-2, "数据异常");
        }
        //附议发起时间
        CDO record = new CDO();
        record.set("essential_information_id", id);
        record.set("vote_type", 0);//0.成立业委会附议
        CDO recordInfo = voteRecordDao.getVoteRecordByCdo(record);
        if (recordInfo != null) {
            voteInfo.set("secondingTime", recordInfo.getString("begin_time"));
        }
        //详细位置
        CDO address = new CDO();
        address.set("community_province", voteInfo.getString("community_province"));
        address.set("community_city", voteInfo.getString("community_city"));
        address.set("community_area", voteInfo.getString("community_area"));
        address = this.getDetailPositionInfoById(address);
        voteInfo.set("city", address.getString("city"));
        voteInfo.set("district", address.getString("district"));
        voteInfo.set("province", address.getString("province"));
        String province = address.getString("province");
        String city = address.getString("city");
        //根据省市名称获取后台设置信息---应根据id
        CDO setInfo = this.getVoteSetInfoByAddress(province, city);
        //获取本次附议所需业主人数及面积
        if (voteInfo != null && setInfo != null) {
            CDO passInfo = this.getPassConditionBySetInfoAndVoteInfo(voteInfo, setInfo);
            if (passInfo != null) {
                setInfo.set("passRoomTotal", passInfo.getString("passRoomTotal"));
                setInfo.set("passAreaTotal", passInfo.getString("passAreaTotal"));
            }
            Integer vote_type = voteInfo.getInteger("vote_type");
            if (vote_type == 2) {
                //解聘物业满足任意一项
                setInfo.set("set_status", 2);
                //解聘物业
                //1.业主 2.业委会委员
                Integer identity_type = voteInfo.getInteger("identity_type");
                //委员人数
                Integer industry_committee_total = voteInfo.getInteger("industry_committee_total");
                if (identity_type == 1) {
                    Double proArea = voteInfo.getDouble("community_areass");
                    Double household_total = voteInfo.getDouble("household_total");
                    //通过票数  附议面积
                    setInfo.set("passRoomTotal", this.getDoubleString(Math.ceil(household_total * 0.2)));
                    setInfo.set("passAreaTotal", this.getDoubleString(Math.ceil(proArea * 0.2)));
                } else if (identity_type == 2) {
                    //需收集票数  已收集票数
                    setInfo.set("passNumberOfVotes", (industry_committee_total / 2 + industry_committee_total % 2));
                    CDO select = new CDO();
                    select.set("essential_information_id", id);
                    select.set("reconsideration_status", 1);
                    setInfo.set("alreadyNumberOfVotes", voteEssentialInformationDao.getVoteUserListByCDOTotal(select));
                }
            }
        }
        //查询标识，展示附议人数信息
        String selectPassNumber = cdoRequest.getString("selectPassNumber");
        if (!StringUtils.isEmpty(selectPassNumber)) {
            //附议人数
            Integer secondedTotal = voteEssentialInformationDao.getNumberOfSecondedProposalsTotal(id);
            secondedTotal = secondedTotal != null ? secondedTotal : 0;
            //百分比 附议人数/小区户数
            Double household_total = voteInfo.getDouble("household_total");
            String ratioStr = this.getDoubleString(Double.parseDouble(secondedTotal.toString()) / household_total * 100) + "%";
            voteInfo.set("secondedTotal", secondedTotal);
            voteInfo.set("ratioStr", ratioStr);
            //附议面积
            Double areSum = voteEssentialInformationDao.getNumberOfSecondedProposalsAreaSum(id);
            areSum = areSum != null ? areSum : 0;
            //百分比 附议面积/小区面积
            Double community_areass = voteInfo.getDouble("community_areass");
            String ratioStrArea = this.getDoubleString(Double.parseDouble(areSum.toString()) / community_areass * 100) + "%";
            voteInfo.set("secondedArea", this.getDoubleString(areSum));
            voteInfo.set("ratioStrArea", ratioStrArea);
            //发起附议记录 存贮了当时发表附议的标准,及最新标准的id 需求不确定 按照当时||按照最新 说是俩都行
            CDO secondedInfo = voteEssentialInformationDao.getVoteSecondedInfoByVoteId(id);
            if (secondedInfo != null) {
                voteInfo.set("secondedId", secondedInfo.getString("id"));
                //用户填写的附议户数多少自动结束
                voteInfo.set("user_room", secondedInfo.getString("user_room"));
                //附议面积多少自动结束
                voteInfo.set("user_area", secondedInfo.getString("user_area"));
            }
        }
        //2023-6-3，fire_property_whether_industry_committee 解聘物业，有无业委会    1.有 2.无
        CDO selectReconsideration = new CDO();
        selectReconsideration.set("essential_information_id", id);
        CDO voteReconsideration = voteReconsiderationDao.getVoteReconsideration(selectReconsideration);
        if (voteReconsideration != null) {
            voteInfo.set("fire_property_whether_industry_committee", voteReconsideration.getString("fire_property_whether_industry_committee"));
        }
        //2023-5-19,解聘物业,批复单位
        String vote_things = voteInfo.getString("vote_things");
        if (!StringUtils.isEmpty(vote_things)) {
            CDO voteThingsCdo = voteInfo.getCDO("vote_things");
            if (voteThingsCdo != null) {
                List<CDO> voteThingsList = voteThingsCdo.getCDOList("voteThingsList");
                List<CDO> voteOtherThingsList = voteThingsCdo.getCDOList("voteOtherThingsList");
                List<String> thingsList = new ArrayList<>();
                for (CDO cdo : voteThingsList) {
                    if (cdo.getBoolean("checkFlag")) {
                        thingsList.add(cdo.getString("text"));
                    }
                }
                for (CDO thingsCdo : voteOtherThingsList) {
                    thingsList.add(thingsCdo.getString("otherThings"));
                }
                voteInfo.set("thingsList", thingsList);
            }
        }
        CDO result = new CDO();
        result.set("voteSet", setInfo);
        result.set("voteInfo", voteInfo);
        return Return.valueOf(result);
    }

    /**
     * 根据设置信息及表决信息查询通过条件
     *
     * @return
     */
    public CDO getPassConditionBySetInfoAndVoteInfo(CDO voteInfo, CDO setInfo) {
        CDO result = new CDO();
        //小区面积
        String pro_area = voteInfo.getString("community_areass");
        pro_area = StringUtils.isEmpty(pro_area) ? "0" : pro_area;
        //小区房间
        String pro_room = voteInfo.getString("household_total");
        pro_room = StringUtils.isEmpty(pro_room) ? "0" : pro_room;
        //数量||百分比
        String roomTotal = setInfo.getString("reconsideration_households");
        roomTotal = StringUtils.isEmpty(roomTotal) ? "0" : roomTotal;
        //面积||百分比
        String areaTotal = setInfo.getString("reconsideration_area");
        areaTotal = StringUtils.isEmpty(areaTotal) ? "0" : areaTotal;
        //0.数量 1.百分比
        String roomState = setInfo.getString("reconsideration_households_state");
        roomState = StringUtils.isEmpty(roomState) ? "0" : roomState;
        String areaState = setInfo.getString("reconsideration_area_state");
        areaState = StringUtils.isEmpty(areaState) ? "0" : areaState;
        //1.满足两项  2.满足一项 3.满足人数  4.满足面积
        String set_status = setInfo.getString("set_status");
        //通过房间数量
        String passRoomTotal = roomState.equals("0") ? roomTotal : this.getDoubleString(Double.parseDouble(pro_room) * Double.parseDouble(roomTotal) * 0.01);
        //通过面积数量
        String passAreaTotal = areaState.equals("0") ? areaTotal : this.getDoubleString(Double.parseDouble(pro_area) * Double.parseDouble(areaTotal) * 0.01);
        //只满足人数，面积为空
        if (set_status.equals("3")) passAreaTotal = null;
        //只满足面积，人数为空
        if (set_status.equals("4")) passRoomTotal = null;
        result.set("passRoomTotal", passRoomTotal);
        result.set("passAreaTotal", passAreaTotal);
        return result;
    }

    public String getDoubleString(double number) {
        String numberStr;
        if (((int) number * 1000) == (int) (number * 1000)) {
            //如果是一个整数
            numberStr = String.valueOf((int) number);
        } else {
            DecimalFormat df = new DecimalFormat("######0.00");
            numberStr = df.format(number);
        }
        return numberStr;
    }

    /**
     * 根据省市查询设置信息
     *
     * @param province
     * @param city
     * @return
     */
    public CDO getVoteSetInfoByAddress(String province, String city) {
        province = StringUtils.isEmpty(province) ? null : province;
        city = StringUtils.isEmpty(city) ? null : city;
        //优先查询市
        CDO select = new CDO();
        select.set("community_city", city);
        CDO setInfoByCity = voteVotingSettingsDao.getSetInfoByCDO(select);
        if (setInfoByCity != null) {
            return setInfoByCity;
        }
        select.set("community_city", null);
        select.set("community_province", province);
        CDO setInfoByProvince = voteVotingSettingsDao.getSetInfoByCDO(select);
        if (setInfoByProvince != null) {
            return setInfoByProvince;
        }
        return null;
    }

    /**
     * 根据省市区获取位置
     *
     * @param address
     * @return
     */
    public CDO getDetailPositionInfoById(CDO address) {
        List<CDO> addressList = voteEssentialInformationDao.getVoteAddressInformation(address);
        String province = "";
        String city = "";
        String district = "";
        for (CDO addressInfo : addressList) {
            String name = addressInfo.getString("name");
            String type = addressInfo.getString("type");
            if (type.equals("province")) province = name;
            if (type.equals("city")) city = name;
            if (type.equals("district")) district = name;
        }
        address.set("province", province);
        address.set("city", city);
        address.set("district", district);
        return address;
    }


    /**
     * 投票列表查询
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return getVoteEssentiPresentInformation(CDO cdoRequest) {
//        cdoRequest.set("recordFrom", 0);
//        cdoRequest.set("recordSize", 100);
//        计算分页
        Integer recordFrom = cdoRequest.getInteger("recordFrom") != null ?cdoRequest.getInteger("recordFrom") :0;
        Integer recordSize =   cdoRequest.getInteger("recordSize")!=null ?cdoRequest.getInteger("recordSize"):10;
        recordFrom = recordFrom * recordSize ;
        //2022-11-8，业主端可查看的投票数据，可根据项目名称来
        //业主端访问接口标识参数 ownerApp--操作人userId
        String ownerApp = cdoRequest.getString("ownerApp");
        String pro_id = cdoRequest.getString("project_id");
        if (!StringUtils.isEmpty(pro_id)) {
            cdoRequest.set("project_id", null);
        }
        List<CDO> voteList = voteEssentialInformationDao.getVoteEssentiPresentInformation(cdoRequest);
        for (CDO voteInfo : voteList) {
            String id = voteInfo.getString("id");
            //到第几大步
            CDO stepInfo = this.getStepInfoById(id);
            if (stepInfo != null) {
                voteInfo.set("vote_steps", stepInfo.getString("voteType"));
                voteInfo.set("small_steps", stepInfo.getString("curStep"));
            }
            voteInfo.set("redDotsTotal", this.getRedDotsTotal(ownerApp, id));
        }
        cdoRequest.set("recordFrom",null);
        List<CDO> voteCountList = voteEssentialInformationDao.getVoteEssentiPresentInformation(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", true);
        cdoResult.set("datalist", voteList);
        cdoResult.set("total", voteCountList.size());
        return Return.valueOf(cdoResult);
    }

    /**
     * 查询该次表决到第几步骤
     *
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return getVoteVotePerformSteps(CDO cdoRequest) {
        String id = cdoRequest.getString("id");
        if (StringUtils.isEmpty(id)) {
            return Return.valueOf(-2, "id不可为空");
        }
        return Return.valueOf(this.getStepInfoById(id));
    }

    /**
     * 根据id获取表决到了第几部
     *
     * @param id
     * @return
     */
    public CDO getStepInfoById(String id) {
        //大步 0 对应投票平台首页
        Integer voteType = 0;
        //小步
        Integer curStep = 1;
        //查询该条数据最后一条步骤记录
        CDO stepInfo = voteStepDao.getNewStepInfoById(id);
        if (stepInfo != null) {
            voteType = stepInfo.getInteger("step_big");
            curStep = stepInfo.getInteger("step_small");
        }
        CDO result = new CDO();
        result.set("curStep", curStep);
        result.set("voteType", voteType);
        result.set("voteEsenId", id);
        return result;
    }


    //   业主端  第二步认证扫描附议 ，弹窗根据id 查询信息接口
    @OpenApi
    public Return getOwnerVoteOpenPopUps(CDO cdoRequest) {
        CDO voteEssentialInformation = voteEssentialInformationDao.getVoteEssentialInformation(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("voteUserDate", voteEssentialInformation);
        return Return.valueOf(cdoResult);
    }




    //====//    生成二维码
    public String rand(String src) {
        Date currTime = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
        String time = formatter.format(currTime);
        String timeMillis = currTime.getTime() + "";
        String item = timeMillis.substring(timeMillis.length() - 4);//时间戳后四位
        String codeItem = RandomStrUtil.getRandInt(3);//随机码四位
        String rand = src + time + item + codeItem;
        return rand;
    }



    //    第二步 点击获取上传信息
    @OpenApi
    public Return getVoteDownExceTemplateInfo(CDO cdoRequest) {
        String id = cdoRequest.getString("id");
        Long templateType = cdoRequest.getLong("templateType");
        if (id == null && templateType == null) {
            return Return.valueOf(-2, "为获取当前主持会议基本");
        }
        CDO voteDownExceTemplateInfo = null;
        if (templateType == 1) {
            voteDownExceTemplateInfo = voteEssentialInformationDao.getVoteDownExceTemplateInfoOne(cdoRequest);
        } else if (templateType == 2) {
            voteDownExceTemplateInfo = voteEssentialInformationDao.getVoteEssentialInformation(cdoRequest);//这个就用
        } else if (templateType == 3) {
            voteDownExceTemplateInfo = voteEssentialInformationDao.getVoteDownExceTemplateInfoTwo(cdoRequest);
        }

//        获取系统设置百分比和信息
        if (templateType == 1) {
            CDO votSet = new CDO();
            votSet.set("essential_information_id", 0);
            votSet.set("essential_information_id", voteDownExceTemplateInfo.getString("address"));
            CDO voteVotingSettings = voteVotingSettingsDao.getVoteVotingSettings(votSet);
            voteDownExceTemplateInfo.set("voteSeting", voteVotingSettings);
        }


        if (templateType == 3) {
            CDO statuteImg = new CDO();
            statuteImg.set("essential_information_id", id);
            List<CDO> voteStatuteImgList = voteStatuteImgDao.getVoteStatuteImgList(statuteImg);
            voteDownExceTemplateInfo.set("voteStaImg", voteStatuteImgList);
        }


        if (voteDownExceTemplateInfo == null) {
            return Return.valueOf(-2, "用户表为查到改信息");

        }

//        设置的面积 和总总户数
        String community_areass = voteDownExceTemplateInfo.getString("community_areass");
        String household_total = voteDownExceTemplateInfo.getString("household_total");


//        查询当前这里的人员一共多少面积 --这里查询附议的
        CDO userCha = new CDO();
        userCha.set("essential_information_id", id);
        userCha.set("reconsideration_status", 1);

        Double all = null;
//        计算面积总和

        CDO voteBuildingArea = voteUserDao.getVoteBuildingArea(userCha);
        if (voteBuildingArea != null) {
            Double moneySum = voteBuildingArea.getDouble("moneySum");
            CDO voteAreaSum = new CDO();
            voteAreaSum.set("name", "附议面积");
            voteAreaSum.set("agree", moneySum.toString());//同意人数
            all = Double.valueOf(community_areass);//总面积
            CDO voteArea = this.getVoteNumber(all, moneySum, voteAreaSum);
            voteDownExceTemplateInfo.set("voteArea", voteArea);
        }

//        计算人员
        List<CDO> voteUserList = voteUserDao.getVoteUserList(userCha);
        if (voteUserList.size() > 0) {
            Double UserListTotal = Double.valueOf(voteUserList.size());//人数总
            CDO userSum = new CDO();
            userSum.set("name", "人员");
            userSum.set("agree", voteUserList.size());//同意人数
            all = Double.valueOf(household_total);//总人数
            CDO voteNumber = this.getVoteNumber(all, UserListTotal, userSum);
            voteDownExceTemplateInfo.set("voteNumber", voteNumber);
        }


        CDO addressInfo = new CDO();
        addressInfo.set("community_province", voteDownExceTemplateInfo.getString("community_province"));
        addressInfo.set("community_city", voteDownExceTemplateInfo.getString("community_city"));
        addressInfo.set("community_area", voteDownExceTemplateInfo.getString("community_area"));
//
        List<CDO> voteAddressInformation = voteEssentialInformationDao.getVoteAddressInformation(addressInfo);
        voteDownExceTemplateInfo.set("addressInfo", voteAddressInformation);//会议位置信息

        voteDownExceTemplateInfo.set("templateType", templateType);
        return Return.valueOf(voteDownExceTemplateInfo);
    }


    public CDO getVoteNumber(Double all, Double selectTotal, CDO cdo) {
        Double ratio = selectTotal / all * 100;
        BigDecimal money = new BigDecimal(ratio);
        ratio = money.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
        cdo.set("ratio", ratio.toString() + "%");
        return cdo;
    }







    //     获取剩余时间戳
    public Long getTimeRemaining(CDO timeCdo) {
        Long numTime = null;
        Date star_time = timeCdo.getDate("star_time");
        Date end_time = timeCdo.getDate("end_time");
        if (star_time != null && end_time != null) {
            Long starTime = star_time.getTime();
            Long endTime = end_time.getTime();
            numTime = endTime - starTime;//时间戳相差的毫秒数
        }
        return numTime;
    }



    // 访问当前登录人信息
    @OpenApi
    public Return getLoggerUserInfoByUserId(CDO cdoRequest) {
        String user_id = cdoRequest.getString("user_id");
        if (user_id == null) {
            return Return.valueOf(-2, "未获取到用户id--user_id");
        }
        CDO sysUserInfoByUserId = voteEssentialInformationDao.getSysUserInfoByUserId(cdoRequest);
        return Return.valueOf(sysUserInfoByUserId);
    }




    //
    public String addVoteOwnerMeeting(CDO voteEsenInfo) {

        CDO addOwerMeet = new CDO();
        addOwerMeet.set("user_id", voteEsenInfo.getString("new_user_id"));
        addOwerMeet.set("essential_information_id", voteEsenInfo.getString("id"));
//        ==这个判断下数据库有数据还是没有
        int voteOwnerMeetingCount = voteOwnerMeetingDao.getVoteOwnerMeetingCount(addOwerMeet);
        addOwerMeet.set("preparation_vote_user_id", voteEsenInfo.getString("preparation_vote_user_id"));
        addOwerMeet.set("proprietor_statute", voteEsenInfo.getString("four_owner_statute_img"));
        addOwerMeet.set("deliberation_rule", voteEsenInfo.getString("four_deliberation_statute_img"));
        addOwerMeet.set("owner_meeting_programme", voteEsenInfo.getString("four_owner_programme_img"));

        addOwerMeet.set("candidate_committe", voteEsenInfo.getString("four_certification_candidate_img"));
        addOwerMeet.set("publicity_picture", voteEsenInfo.getString("six_convene_template_img"));
        addOwerMeet.set("meeting_time", voteEsenInfo.getString("six_holding_time"));
        addOwerMeet.set("expand_time", voteEsenInfo.getString("six_expand_time"));
        addOwerMeet.set("committee_number", voteEsenInfo.getString("four_members_number"));
        addOwerMeet.set("replenish_number", voteEsenInfo.getString("four_replenish_members_number"));
        addOwerMeet.set("director_number", voteEsenInfo.getString("four_directors__number"));
        addOwerMeet.set("deputy_director_number", voteEsenInfo.getString("four_deputy_directors__number"));
        if (voteOwnerMeetingCount == 0) {
            voteOwnerMeetingDao.addVoteOwnerMeeting(addOwerMeet);//没有添加
        } else {//修改信息
//            获取修改id
            CDO voteOwnerMeeting = voteOwnerMeetingDao.getVoteOwnerMeeting(addOwerMeet);
            if (voteOwnerMeeting != null) {
                addOwerMeet.set("id", voteOwnerMeeting.getLong("id"));
                voteOwnerMeetingDao.updateVoteOwnerMeetingById(addOwerMeet);//有修改
            }
        }
        String voOwMetId = null;


        voOwMetId = addOwerMeet.getString("id");

        return voOwMetId;
    }



    //作废 ，我这=一个人一个list不展示其他信息
    @OpenApi
    public Return getVoteEightVoteInfo(CDO cdoRequest) {
        Long id = cdoRequest.getLong("essential_information_id");

        CDO voteEssentialInformationById = voteEssentialInformationDao.getVoteEssentialInformationById(Math.toIntExact(id));
        if (voteEssentialInformationById == null) {
            return Return.valueOf(-2, "未获取信息");
        }

        List<CDO> voteUserList = voteRecommendDao.getVoteUserRecommendInfo(cdoRequest);
        for (CDO userLisr : voteUserList) {
            Long vote_user_id = userLisr.getLong("vote_user_id");
            CDO voteRecCdo = new CDO();
            voteRecCdo.set("recommend_state", cdoRequest.getString("recommend_state"));
            voteRecCdo.set("essential_information_id", cdoRequest.getString("essential_information_id"));
            List<CDO> voteRecommendList = voteRecommendDao.getVoteRecommendList(voteRecCdo);
            for (CDO recom : voteRecommendList) {
                String id1 = recom.getString("vote_user_id");
                voteRecCdo.set("vote_user_id", id1);
                int voteRecommendCount = voteRecommendDao.getVoteRecommendCount(voteRecCdo);
                recom.set("numberVotes", voteRecommendCount);
            }
            userLisr.set("voteRec", voteRecommendList);
//            查看自己票数
            voteRecCdo.set("vote_user_id", vote_user_id);
            int voteRecommendCount = voteRecommendDao.getVoteRecommendCount(voteRecCdo);
            userLisr.set("agree", voteRecommendCount);

//            人员拒绝
            userLisr.set("refuses", voteUserList.size() - voteRecommendCount);

        }


        voteEssentialInformationById.set("userLisr", voteUserList);
        return Return.valueOf(voteEssentialInformationById);
    }



    /**
     * 添加首次成立业委会基本信息记录表,获取id数据
     *
     * @param cdoRequest - id:
     *                   - user_id:用户id
     *                   - vote_step_id:推进步骤id
     *                   - community_areass:小区面积
     *                   - community_name:小区名称
     *                   - community_position:小区位置
     *                   - community_province:省
     *                   - community_city:市
     *                   - community_area:区/县
     *                   - community_voucher_img:社区总面积凭证
     *                   - household_total:总户数
     *                   - full_name:姓名
     *                   - telephone:电话
     *                   - building_number:楼号
     *                   - preparation_status:是否有筹备组队长：0、无，1、有
     *                   - preparation_vote_user_id:筹备组组长id
     *                   - preparation_name:筹备组组长姓名
     *                   - preparation_telephone:筹备组组长电话
     *                   - preparation_company:筹备组组长单位
     *                   - preparations_number:筹备组人数
     *                   - preparations_start_time:开始报名时间
     *                   - preparations_end_time:结束报名时间
     *                   - preparations_vote:筹备组候选人投票时间
     *                   - apply_reconsideration_total:申请复议总户数
     *                   - apply_reconsideration_area:申请复议总面积
     *                   - four_owner_statute_img:业主规约线下公示图片
     *                   - four_deliberation_statute_img:议事规约线下公示图片
     *                   - four_owner_programme_img:业主大会方案线下公示图片
     *                   - four_certification_candidate_img:认证候选委员方案下公示图片
     *                   - four_members_number:委员人数
     *                   - four_replenish_members_number:后补委员人数
     *                   - four_directors__number:主任人数
     *                   - four_deputy_directors__number:副主任人数
     *                   - four_publicity_time:业主端公示时间
     *                   - four_publicity_end_time:业主端公示结束时间
     *                   - five_registration_time:委员报名时间
     *                   - five_registration_end_time:委员报名结束时间
     *                   - five_recruit:招募公告
     *                   - five_recruit_img:上传线下公告图片
     *                   - six_end_voting:投票达到法定要求提前结束：1是，0否
     *                   - six_holding_time:召开大会开始时间
     *                   - six_holding_end_time:召开大会结束时间
     *                   - six_expand_time:可延长时间
     *                   - six_meeting_place:会议地点
     *                   - six_voting_method:投票方式：1助业app，2、书面投票
     *                   - six_convene_template:公示首次业主大会通知模板
     *                   - six_convene_template_img:上传线下公示图片
     *                   - seven_offline_img:线下投票凭证
     *                   - seven_offline_publicity_img:委员线下公示照片
     *                   - begin_time:创建时间
     *                   - update_time:更新时间
     *                   - state:删除，0正常1删除
     * @return
     * @author ht
     * @create: 2022-07-08 19:04:49
     */
    @OpenApi
    public Return addVoteEssentialInformation(CDO cdoRequest) {
        voteEssentialInformationDao.addVoteEssentialInformation(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("id")) {
            cdoResult.set("id", cdoRequest.get("id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，更新首次成立业委会基本信息记录表数据
     *
     * @return
     * @author ht
     * @create: 2022-07-08 19:04:49
     */
    @OpenApi
    public Return updateVoteEssentialInformationById(CDO cdoRequest) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        //update_time,在判断第6步骤，三天后筹备组自动同意使用
        cdoRequest.set("update_time", sdf.format(new Date()));
        int affectedRows = voteEssentialInformationDao.updateVoteEssentialInformationById(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        cdoResult.set("cdoRequest", cdoRequest);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，删除首次成立业委会基本信息记录表数据
     *
     * @param cdoRequest - id:
     * @return
     * @author ht
     * @create: 2022-07-08 19:04:49
     */
    @OpenApi
    public Return deleteVoteEssentialInformationById(CDO cdoRequest) {
        int affectedRows = voteEssentialInformationDao.deleteVoteEssentialInformationById(cdoRequest.getInteger("id"));
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除首次成立业委会基本信息记录表数据
     *
     * @param cdoRequest
     * @return
     * @author ht
     * @create: 2022-07-08 19:04:49
     */
    @OpenApi
    public Return deleteVoteEssentialInformation(CDO cdoRequest) {
        int affectedRows = voteEssentialInformationDao.deleteVoteEssentialInformation(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取首次成立业委会基本信息记录表数据
     *
     * @param cdoRequest - id:
     * @return
     * @author ht
     * @create: 2022-07-08 19:04:49
     */
    @OpenApi
    public Return getVoteEssentialInformationById(CDO cdoRequest) {
        CDO cdoMapperResult = voteEssentialInformationDao.getVoteEssentialInformationById(cdoRequest.getInteger("id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据混合条件，获取首次成立业委会基本信息记录表数据
     *
     * @param cdoRequest - id:
     * @return
     * @author ht
     * @create: 2022-07-08 19:04:49
     */

    @OpenApi
    public Return getVoteEssentialInformation(CDO cdoRequest) {
        CDO cdoMapperResult = voteEssentialInformationDao.getVoteEssentialInformation(cdoRequest);
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取首次成立业委会基本信息记录表数据列表
     *
     * @param cdoRequest
     * @return
     * @author ht
     * @create: 2022-07-08 19:04:49
     */
    @OpenApi
    public Return getVoteEssentialInformationList(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.containsKey("pageIndex") ? cdoRequest.getInteger("pageIndex") : 0;
        int recordSize = cdoRequest.containsKey("recordSize") ? cdoRequest.getInteger("recordSize") : 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = voteEssentialInformationDao.getVoteEssentialInformationList(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
        int total = voteEssentialInformationDao.getVoteEssentialInformationListByConditionCount(cdoRequest);
        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据混合条件，获取首次成立业委会基本信息记录表数据列表
     *
     * @param cdoRequest - id:
     * @return
     * @author ht
     * @create: 2022-07-08 19:04:49
     */
    @OpenApi
    public Return getVoteEssentialInformationListByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.containsKey("pageIndex") ? cdoRequest.getInteger("pageIndex") : 0;
        int recordSize = cdoRequest.containsKey("recordSize") ? cdoRequest.getInteger("recordSize") : 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = voteEssentialInformationDao.getVoteEssentialInformationListByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = voteEssentialInformationDao.getVoteEssentialInformationListByConditionCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
